ServiceResolver.GenericHost is an abstract library for .NET generic host, using ServiceResolver.Ioc integration.
$ dotnet add package ServiceResolver.GenericHostServiceResolver.GenericHost is an abstract library for .NET generic host, which uses ServiceResolver.Ioc library.
Take this example defining a new IServiceRegisterProvider implementation (or other third party IServiceRegisterProvider implementation).
class CustomServiceRegisterProvider : IServiceRegisterProvider
{
public CustomServiceRegisterProvider(CustomServiceRegisterDescriptor descriptor)
{
// coding for setup.
}
// your custom implementation ..
}
The extension method UseServiceResolver has as input the ServiceRegisterOptions instance.
var hostBuilder = Host.CreateDefaultBuilder(args)
// custom extension method to use for integration.
.UseServiceResolver(new ServiceRegisterOptions<IServiceRegisterProvider>
{
// a factory used to create your service register provider
OnCreating = collection =>
{
return new CustomServiceRegisterProvider(new CustomServiceRegisterDescriptor());
},
// (optional)
// an action used to prepare (if needed) your IServiceCollection.
BeforeRegistering = collection =>
{
// your IServiceCollection registrations or integrations
},
// an action used to register your services.
OnRegistering = provider =>
{
// example:
provider.Register<StringBuilder>(() => new StringBuilder("hello world.."));
},
// (optional)
// an action used to executes custom action at the end of all previous steps.
AfterBuildingProvider = provider =>
{
}
});
var host = hostBuilder.Build();
await host.RunAsync();
The extension method UseServiceResolver has as input the HostBuilderContext instance in the lambda expression, and that reference can be used inside the factory function.
var hostBuilder = Host.CreateDefaultBuilder(args)
// custom extension method to use for integration.
.UseServiceResolver(context => new ServiceRegisterOptions<IServiceRegisterProvider>
{
// a factory used to create your service register provider
OnCreating = collection =>
{
return new CustomServiceRegisterProvider(new CustomServiceRegisterDescriptor());
},
// (optional)
// an action used to prepare (if needed) your IServiceCollection.
BeforeRegistering = collection =>
{
// your IServiceCollection registrations or integrations
},
// an action used to register your services.
OnRegistering = provider =>
{
// example:
provider.Register<StringBuilder>(() => new StringBuilder("hello world.."));
},
// (optional)
// an action used to executes custom action at the end of all previous steps.
AfterBuildingProvider = provider =>
{
}
});
var host = hostBuilder.Build();
await host.RunAsync();
The main types provided by this library are:
ServiceResolver.Ioc.Options.ServiceRegisterOptions<TServiceRegister>ServiceResolver.Ioc.Options.ServiceRegisterOptionsServiceResolver.Ioc.Options.IServiceRegisterBuilderServiceResolver.Ioc.Providers.ServiceResolverScopeFactoryServiceResolver.Ioc.Providers.IServiceProviderAdapterServiceResolver.Ioc.Providers.ServiceResolverBuilder<TServiceRegister>Microsoft.Extensions.HostingServiceResolver.Ioc