Replacing ServiceStack Funq IoC

In the AppHost class, all method overrides use the Funq container. I use Autofac in my ASP.NET MVC application (I run SS side by side with my MVC application).

  • Is there a way to use this Autofac registry from global.asax.cs or is this overflow for replacement?
  • I commented on this line in AppHost

    //ControllerBuilder.Current.SetControllerFactory (new FunqControllerFactory (container));

because it messed up my controllers running on Autofac. Is this enough to prevent errors in Autofac and Funq from appearing in my application? Or did Funq set itself as the default DependencyResolversomewhere else?

+5
source share
2 answers

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 Configure () :

//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;
+9

autofac , . . IContainerAdapter, :

fooobar.com/questions/1126526/...

+4

All Articles