Dependency Injection
Services and Dependency Injection in 3.1.
Registering Services
static Program() {
// Register an ILogger service implemented by MyLogger as a global shared singleton.
Application.Services.AddService<ILogger, MyLogger>();
// Register an IFileSystem service where the implementation is crated by the CreateFileSystemFactory method
// and scope is set to be the session.
Application.Services.AddService<IFileSystem>(CreateFileSystemFactory, ServiceLifetime.Session);
}
private static IFileSystem CreateFileSystemFactory(Type serviceType) {
return new MyFileSystemImplementation();
}Using a Service
Service Injection
Generic Service Type
Alternative IServiceProvider
Services Lifetime
Last updated
Was this helpful?

