add: BlogApplication基架

This commit is contained in:
jackfiled 2024-01-16 20:33:39 +08:00
parent 1abc2ff933
commit b12aa481e1
10 changed files with 110 additions and 55 deletions

View File

@ -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);
}
}

View File

@ -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<TContainerBuilder>(
IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null)
where TContainerBuilder : notnull
=> _hostApplicationBuilder.ConfigureContainer(factory, configure);
public IDictionary<object, object> 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;
}

View File

@ -0,0 +1,6 @@
namespace YaeBlog.Core.Builder;
public class BlogApplicationOptions
{
public string[]? Args { get; init; }
}

View File

@ -1,3 +0,0 @@
<div class="my-component">
This component is defined in the <strong>YaeBlog.Core</strong> library.
</div>

View File

@ -1,6 +0,0 @@
.my-component {
border: 2px dashed red;
padding: 1em;
margin: 1em 0;
background-image: url('background.png');
}

View File

@ -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<Task<IJSObjectReference>> moduleTask;
public ExampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new (() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/YaeBlog.Core/exampleJsInterop.js").AsTask());
}
public async ValueTask<string> Prompt(string message)
{
var module = await moduleTask.Value;
return await module.InvokeAsync<string>("showPrompt", message);
}
public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
}
}
}

View File

@ -12,7 +12,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Markdig" Version="0.34.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -20,4 +22,8 @@
<None Include="../.editorconfig" /> <None Include="../.editorconfig" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project> </Project>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 B

View File

@ -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');
}

2
YaeBlog.sln.DotSettings Normal file
View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Markdig/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>