Make vault storages work
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class Component :
|
||||
IComponent
|
||||
{
|
||||
private readonly IComponentBuilder builder;
|
||||
|
||||
protected Component(IComponentBuilder builder)
|
||||
{
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public static TComponent? Create<TComponent>(IServiceProvider provider,
|
||||
Action<IComponentBuilder> builderDelegate)
|
||||
where TComponent : class, IComponent
|
||||
{
|
||||
if (provider.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
||||
{
|
||||
IComponentBuilder builder = ComponentBuilder.Create();
|
||||
builderDelegate(builder);
|
||||
|
||||
return factory.Create<TComponent>(builder);
|
||||
}
|
||||
return default ;
|
||||
}
|
||||
|
||||
public virtual IComponentBuilder Create() => builder;
|
||||
}
|
||||
Reference in New Issue
Block a user