1

在 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);
    }**
}
4

0 回答 0