diff --git a/YaeBlog.Core/Builder/BlogApplication.cs b/YaeBlog.Core/Builder/BlogApplication.cs new file mode 100644 index 0000000..cfd6283 --- /dev/null +++ b/YaeBlog.Core/Builder/BlogApplication.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Hosting; + +namespace YaeBlog.Core.Builder; + +public class BlogApplication : IHost +{ + private readonly IHost _host; + + internal BlogApplication(IHost host) + { + _host = host; + } + + public static BlogApplicationBuilder Create(string[] args) + { + BlogApplicationOptions options = new() { Args = args }; + return new BlogApplicationBuilder(options); + } + + public Task StartAsync(CancellationToken cancellationToken = new()) + { + return _host.StartAsync(cancellationToken); + } + + public Task StopAsync(CancellationToken cancellationToken = new()) + { + return _host.StopAsync(cancellationToken); + } + + public IServiceProvider Services => _host.Services; + + public Task RunAsync() => _host.RunAsync(); + + public void Run() => _host.Run(); + + public void Dispose() + { + _host.Dispose(); + GC.SuppressFinalize(this); + } +} diff --git a/YaeBlog.Core/Builder/BlogApplicationBuilder.cs b/YaeBlog.Core/Builder/BlogApplicationBuilder.cs new file mode 100644 index 0000000..b284137 --- /dev/null +++ b/YaeBlog.Core/Builder/BlogApplicationBuilder.cs @@ -0,0 +1,51 @@ +using Markdig; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.Metrics; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using YaeBlog.Core.Extensions; + +namespace YaeBlog.Core.Builder; + +public sealed class BlogApplicationBuilder : IHostApplicationBuilder +{ + private readonly HostApplicationBuilder _hostApplicationBuilder; + + public MarkdownPipelineBuilder MarkdigPipelineBuilder { get; set; } + + internal BlogApplicationBuilder(BlogApplicationOptions options) + { + ConfigurationManager configuration = new(); + MarkdigPipelineBuilder = new MarkdownPipelineBuilder(); + + _hostApplicationBuilder = new HostApplicationBuilder(new HostApplicationBuilderSettings + { + Args = options.Args, Configuration = configuration + }); + } + + public BlogApplication Build() + { + this.ConfigureBlogApplication(); + return new BlogApplication(_hostApplicationBuilder.Build()); + } + + public void ConfigureContainer( + IServiceProviderFactory factory, Action? configure = null) + where TContainerBuilder : notnull + => _hostApplicationBuilder.ConfigureContainer(factory, configure); + + public IDictionary Properties + => (_hostApplicationBuilder as IHostApplicationBuilder).Properties; + + public IHostEnvironment Environment => _hostApplicationBuilder.Environment; + + public IConfigurationManager Configuration => _hostApplicationBuilder.Configuration; + + public ILoggingBuilder Logging => _hostApplicationBuilder.Logging; + + public IMetricsBuilder Metrics => _hostApplicationBuilder.Metrics; + + public IServiceCollection Services => _hostApplicationBuilder.Services; +} diff --git a/YaeBlog.Core/Builder/BlogApplicationOptions.cs b/YaeBlog.Core/Builder/BlogApplicationOptions.cs new file mode 100644 index 0000000..b1f87af --- /dev/null +++ b/YaeBlog.Core/Builder/BlogApplicationOptions.cs @@ -0,0 +1,6 @@ +namespace YaeBlog.Core.Builder; + +public class BlogApplicationOptions +{ + public string[]? Args { get; init; } +} diff --git a/YaeBlog.Core/Component1.razor b/YaeBlog.Core/Component1.razor deleted file mode 100644 index 7f7fda0..0000000 --- a/YaeBlog.Core/Component1.razor +++ /dev/null @@ -1,3 +0,0 @@ -
- This component is defined in the YaeBlog.Core library. -
diff --git a/YaeBlog.Core/Component1.razor.css b/YaeBlog.Core/Component1.razor.css deleted file mode 100644 index c6afca4..0000000 --- a/YaeBlog.Core/Component1.razor.css +++ /dev/null @@ -1,6 +0,0 @@ -.my-component { - border: 2px dashed red; - padding: 1em; - margin: 1em 0; - background-image: url('background.png'); -} diff --git a/YaeBlog.Core/ExampleJsInterop.cs b/YaeBlog.Core/ExampleJsInterop.cs deleted file mode 100644 index 4a5f94b..0000000 --- a/YaeBlog.Core/ExampleJsInterop.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.JSInterop; - -namespace YaeBlog.Core; - -// This class provides an example of how JavaScript functionality can be wrapped -// in a .NET class for easy consumption. The associated JavaScript module is -// loaded on demand when first needed. -// -// This class can be registered as scoped DI service and then injected into Blazor -// components for use. - -public class ExampleJsInterop : IAsyncDisposable -{ - private readonly Lazy> moduleTask; - - public ExampleJsInterop(IJSRuntime jsRuntime) - { - moduleTask = new (() => jsRuntime.InvokeAsync( - "import", "./_content/YaeBlog.Core/exampleJsInterop.js").AsTask()); - } - - public async ValueTask Prompt(string message) - { - var module = await moduleTask.Value; - return await module.InvokeAsync("showPrompt", message); - } - - public async ValueTask DisposeAsync() - { - if (moduleTask.IsValueCreated) - { - var module = await moduleTask.Value; - await module.DisposeAsync(); - } - } -} diff --git a/YaeBlog.Core/YaeBlog.Core.csproj b/YaeBlog.Core/YaeBlog.Core.csproj index eafee1c..67ea826 100644 --- a/YaeBlog.Core/YaeBlog.Core.csproj +++ b/YaeBlog.Core/YaeBlog.Core.csproj @@ -8,16 +8,22 @@ - + - + + + - - + + + + + + diff --git a/YaeBlog.Core/wwwroot/background.png b/YaeBlog.Core/wwwroot/background.png deleted file mode 100644 index e15a3bd..0000000 Binary files a/YaeBlog.Core/wwwroot/background.png and /dev/null differ diff --git a/YaeBlog.Core/wwwroot/exampleJsInterop.js b/YaeBlog.Core/wwwroot/exampleJsInterop.js deleted file mode 100644 index ea8d76a..0000000 --- a/YaeBlog.Core/wwwroot/exampleJsInterop.js +++ /dev/null @@ -1,6 +0,0 @@ -// This is a JavaScript module that is loaded on demand. It can export any number of -// functions, and may import other JavaScript modules if required. - -export function showPrompt(message) { - return prompt(message, 'Type anything here'); -} diff --git a/YaeBlog.sln.DotSettings b/YaeBlog.sln.DotSettings new file mode 100644 index 0000000..3a93f7c --- /dev/null +++ b/YaeBlog.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file