Add a new method to IContainerAdapter interface to support Resolving with name parameters
I am using ServiceStack with Autofac IoC.
There is code provided for wiring up the AutofacIocAdapter as the default resolver for ServiceStack (instead of Funq).
There are two method currently exposed on the IContanerAdapter interface which is used to expose wiring.
It would be useful to expose another method to resolve registered components with named parameters .
It would be very easy as the underlying IContainer interface already exposes this methed.
So, something like
public class AutofacIocAdapter : IContainerAdapter
private readonly IContainer _container;
public AutofacIocAdapter(IContainer container)
_container = container;
public T Resolve<T>()
public T Resolve<T>(NamedParameter parameter)
public T TryResolve<T>()
if (_container.TryResolve<T>(out result))
where public T Resolve<T>(NamedParameter parameter) method would be the new method to expose
Drazen Dotlic commented
There is no need for this.
What you need to do is let ServiceStack's adapter be used only by ServiceStack itself and you should use full power of Autofac yourself. ServiceStack uses a custom build of Funq as IOC/DI library whose API is in no way (it doesn't even try) as feature rich as Autofac's. Forcing the two APIs to align would be akin to fitting a round peg in a square hole.
This does mean that you should:
1. Modularize your app
2. Make sure all dependencies are registered before your service starts running - IOW, don't resolve "manually" (it's a bad practice anyway)
We've had great success with this kind of approach and run things in production for 2+ years like this just fine.