AutoFac等效于此ninject命令/功能

时间:2018-06-05 07:32:11

标签: autofac autofac-configuration autofactory

在Ninject中,我可以配置如下所述的容器,“突出显示的”的Autofac等价物是什么?

目前我正在尝试使用AutoFac实现相同目标,我们非常感谢任何帮助。

 public class NinjectAdapter : IContainerAdapter
 {
    private readonly IKernel _kernel;

    public NinjectAdapter(IKernel kernel)
    {
        _kernel = kernel;
    }

    **public void Register(Type service, Type implementation)
    {
        _kernel.Bind(service).To(implementation);
    }**

    **public void Register(Type service, Type implementation, Type conditionType)
    {
        _kernel.Bind(service).To(implementation).WhenInjectedInto(conditionType);
    }**

    **public void Register(Type service, Type implementation, string named)
    {
        _kernel.Bind(service).To(implementation).Named(named);
    }**

    **public void RegisterSingleton(Type service, Type implementation)
    {
        _kernel.Bind(service).To(implementation).InSingletonScope();
    }**

    **public void RegisterInScope(Type service, Type implementation)
    {
        _kernel.Bind(service).To(implementation).InScope(scope => HttpContext.Current);
    }**


    **public void RegisterInstance(Type service, object instance)
    {
        _kernel.Bind(service).ToConstant(instance);
    }**

    **public void RegisterInstance(Type service, object instance, string named)
    {
        _kernel.Bind(service).ToConstant(instance).Named(named);
    }**
}

0 个答案:

没有答案