Remove connected specific files
This commit is contained in:
parent
f62c1f267e
commit
82594cff34
63
Instance.cs
63
Instance.cs
@ -1,63 +0,0 @@
|
|||||||
using Connected.Middleware;
|
|
||||||
using Connected.Startup;
|
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Connected;
|
|
||||||
|
|
||||||
public static class Instance
|
|
||||||
{
|
|
||||||
public static WebAssemblyHost Host { get; private set; } = default!;
|
|
||||||
private static IServiceProvider ServiceProvider { get; set; } = default!;
|
|
||||||
|
|
||||||
internal static T? GetService<T>()
|
|
||||||
{
|
|
||||||
return ServiceProvider.GetService<T>();
|
|
||||||
}
|
|
||||||
public static async Task Start<TApp>(List<IStartup> startups, Dictionary<string, string> args) where TApp : IComponent
|
|
||||||
{
|
|
||||||
var builder = WebAssemblyHostBuilder.CreateDefault(UnpackArguments(args));
|
|
||||||
|
|
||||||
builder.RootComponents.Add<TApp>("#app");
|
|
||||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
|
||||||
|
|
||||||
builder.Services.AddHttpClient();
|
|
||||||
|
|
||||||
builder.Services.AddSingleton(typeof(IComponentMiddlewareService), typeof(ComponentMiddlewareService));
|
|
||||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
|
||||||
|
|
||||||
foreach (var startup in startups)
|
|
||||||
await startup.ConfigureServices(builder.Services);
|
|
||||||
|
|
||||||
Host = builder.Build();
|
|
||||||
|
|
||||||
foreach (var startup in startups)
|
|
||||||
await startup.Configure(Host);
|
|
||||||
|
|
||||||
await Host.RunAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string[] UnpackArguments(Dictionary<string, string> args)
|
|
||||||
{
|
|
||||||
var result = new string[args.Count];
|
|
||||||
|
|
||||||
for (var i = 0; i < args.Count; i++)
|
|
||||||
{
|
|
||||||
var arg = args.ElementAt(i);
|
|
||||||
|
|
||||||
result[i] = string.IsNullOrWhiteSpace(arg.Value) ? arg.Key : $"{arg.Key}={arg.Value}";
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UseMiddlewareComponent<TMiddleware, TComponent>(this WebAssemblyHost app)
|
|
||||||
{
|
|
||||||
if (app.Services.GetService<IComponentMiddlewareService>() is not IComponentMiddlewareService service)
|
|
||||||
throw new NullReferenceException(nameof(IComponentMiddlewareService));
|
|
||||||
|
|
||||||
service.Add<TMiddleware, TComponent>();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user