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