This is not a bug report but a discussion about the design of DI componments in Nancy.
I notice Nancy work perfectly with Ninja, Autofac, Unity, etc. However I found it impossible to use Microsoft.Extensions.DependencyInjection framework in Nancy.
I recommend to support it because it provide a common interface for different DI frameworks just like what Common.Logging does. It's valuable for users to use a abstract interface against diverse frameworks.
The key point MS DI framework cannot fit into Nancy is it use a 2-step way to build a service resolver. The main idea is to use IServiceCollection for service register and IServiceProvider for the service resolving. IServiceProvider also maintain the scoped lifetime for resolved service from it.
Nancy regard them as one unified thing IContainer, which made it impossible to work with MS DI framework. I suggest to refactor our code to seperate the IContainer into 2 parts as different actors, which would work perfactly with MS DI framework. It would also work fine with the existing codes if we fill in the same type for the 2 actors.
To make it clear, I want
class NancyBootstrapperWithRequestContainerBase<TServiceCollection, TServiceProvider>
instead of
class NancyBootstrapperWithRequestContainerBase<TContainer>
And we are able to keep the compatibility with existing code by
class NinjaBootstrapper : NancyBootstrapperWithRequestContainerBase<TContainer, TContainer>
This is not a bug report but a discussion about the design of DI componments in Nancy.
I notice Nancy work perfectly with Ninja, Autofac, Unity, etc. However I found it impossible to use Microsoft.Extensions.DependencyInjection framework in Nancy.
I recommend to support it because it provide a common interface for different DI frameworks just like what Common.Logging does. It's valuable for users to use a abstract interface against diverse frameworks.
The key point MS DI framework cannot fit into Nancy is it use a 2-step way to build a service resolver. The main idea is to use
IServiceCollection
for service register andIServiceProvider
for the service resolving.IServiceProvider
also maintain the scoped lifetime for resolved service from it.Nancy regard them as one unified thing
IContainer
, which made it impossible to work with MS DI framework. I suggest to refactor our code to seperate theIContainer
into 2 parts as different actors, which would work perfactly with MS DI framework. It would also work fine with the existing codes if we fill in the same type for the 2 actors.To make it clear, I want
instead of
And we are able to keep the compatibility with existing code by