leo*_*ora 1 asp.net-mvc ninject
我看到Ninject与asp.net-mvc 集成有一个扩展,但看起来我可以将Ninject与mvc完美集成而没有这个扩展.例如:
public class NinjectDependencyResolver : IDependencyResolver
    {
        private readonly IResolutionRoot _resolutionRoot;
    public NinjectDependencyResolver(IResolutionRoot resolutionRoot)
    {
        _resolutionRoot = resolutionRoot;
    }
    public object GetService(Type serviceType)
    {
        return _resolutionRoot.TryGet(serviceType);
    }
    public IEnumerable<object> GetServices(Type serviceType)
    {
        return _resolutionRoot.GetAll(serviceType);
    }
}
public class MvcApplication : HttpApplication
{
    void Application_Start()
    {
        var modules = new INinjectModule[] { new ServiceModule() };
        var kernel = new StandardKernel(modules);
        DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
这是一些遗留扩展还是仍然相关?我看到源代码的最新更新,所以我有点困惑
您可以实现自己的依赖关系解析器.所以是的,你不需要它.你可以很容易地集成Ninject而不需要扩展.但问题是你为什么要这样做?Ninject.MVC3扩展提供了添加对Ninject的支持的所有内容,而无需实现自己的依赖关系解析器.这有几个好处:
| 归档时间: | 
 | 
| 查看次数: | 305 次 | 
| 最近记录: |