Add foundation
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ComponentInitializer(IEnumerable<IComponent> components,
|
||||
IProxyServiceCollection<IComponentBuilder> typedServices,
|
||||
IComponentHostCollection hosts,
|
||||
IComponentScopeCollection scopes,
|
||||
IServiceProvider provider) :
|
||||
IInitializer
|
||||
{
|
||||
public async Task Initialize()
|
||||
{
|
||||
foreach (IComponent component in components)
|
||||
{
|
||||
IComponentBuilder builder = component.Create();
|
||||
builder.AddServices(services =>
|
||||
{
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IProxyService<IPublisher>>());
|
||||
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IProxyService<IComponentHostCollection>>());
|
||||
|
||||
services.AddScoped(_ =>
|
||||
provider.GetRequiredService<INavigationContextCollection>());
|
||||
|
||||
services.AddScoped(_ =>
|
||||
provider.GetRequiredService<INavigationContextProvider>());
|
||||
|
||||
services.AddScoped(_ =>
|
||||
provider.GetRequiredService<IComponentScopeCollection>());
|
||||
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IComponentScopeProvider>());
|
||||
|
||||
services.AddRange(typedServices.Services);
|
||||
});
|
||||
|
||||
IComponentHost host = builder.Build();
|
||||
|
||||
scopes.Add(component.GetType().Name,
|
||||
host.Services.GetRequiredService<IServiceProvider>());
|
||||
|
||||
hosts.Add(host);
|
||||
await host.StartAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user