Func和AutoFac可以一起工作。使用ServiceStack指示func使用AutoFac適配器。這裏的這個頁面告訴你如何使用不同的IoC容器。它甚至提供了一個AutofacIocAdapter類的代碼。 https://github.com/ServiceStack/ServiceStack/wiki/The-IoC-container
public class AutofacIocAdapter : IContainerAdapter
{
private readonly IContainer _container;
public AutofacIocAdapter(IContainer container)
{
_container = container;
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
public T TryResolve<T>()
{
T result;
if (_container.TryResolve<T>(out result))
{
return result;
}
return default(T);
}
}
然後在APPHOST配置(集裝箱貨櫃)方法,你需要啓用這個適配器:
//Create Autofac builder
var builder = new ContainerBuilder();
//Now register all depedencies to your custom IoC container
//...
//Register Autofac IoC container adapter, so ServiceStack can use it
IContainerAdapter adapter = new AutofacIocAdapter(builder.Build())
container.Adapter = adapter;
FunqControllerFactory的IMPL可能有助於在這裏:https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.FluentValidation.Mvc3/Mvc /FunqControllerFactory.cs在SocialBootstrapApi中使用它:https://github.com/ServiceStack/SocialBootstrapApi/blob/master/src/SocialBootstrapApi/App_Start/AppHost.cs#L131沒有其他IOC與MVC + Funq集成比FunqControllerFactory – mythz