MVC Ninject:如何从一个MVC区项目中添加NinJect绑定 [英] MVC Ninject: How to add NinJect bindings from an MVC Area project

查看:239
本文介绍了MVC Ninject:如何从一个MVC区项目中添加NinJect绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用这个博客例如:

I've been using this blog example:

http://blog.longle.net/2012/03/29/building-a-composite-mvc3-application-with-pluggable-areas/

我在我的解决方案工作的概念。不过,我想弄清楚,如果用户有权限访问一个模块/地区的好方法只添加绑定到内核中。

I have the concepts working in my solution. However, I'm trying to figure out a good way only add bindings to the kernel if a user has permissions to access a module/area.

我读了一些关于服务定位,但我试图远离它。

I've read up some on the ServiceLocator but I was trying to stay away from it.

有一件事我想只是把事情的工作是用户构造器注入的模块默认构造函数。它的工作不过是一个黑客。

One thing I'm trying just to get things to work is user Contructor injection in the default constructor for a module. It's working but is a hack.

我使用的模式,每个模块项目创建,从AreaRegistion继承一个类。当每个模块项目建立,相关的文件复制到主Web项目的地区文件夹中。然后,当主体工程负荷,反思是用来加载所有模块组件。然后,当AreaRegistration.RegisterAllAreas()被调用时,它会检测并加载与继承AreaRegistration一类的所有模块。

The pattern I'm using, each module project you create an class that inherits from AreaRegistion. When each module project builds, relevant files are copied to the Areas folder of the main web project. Then when the main project loads, reflection is used to load all module assemblies. Then when AreaRegistration.RegisterAllAreas() is called, it detects and loads all the modules with a class that inherits AreaRegistration.

我想弄清楚访问Ninject内核,并从AreaRegistration继承模块类添加绑定一个好办法。我会想象启动code从RegisterArea()重写添加绑定。

I'd like to figure out an good way to access the Ninject kernel and add bindings in the module class that inherits from AreaRegistration. I would imagine initiating code to add bindings from the RegisterArea() override.

我在寻找如何做到这一点的任何建议,而不诉诸服务定位。

I'm looking for any suggestions on how to do this without resorting to the ServiceLocator.

任何意见将大大AP preciated。

Any ideas would be greatly appreciated.

推荐答案

现在我已经找到了更好的解决方案,这就是使用NinjectModule。在插件类中,我将创建一个由NinjectModule继承的类。然后设置在负载过载pluging绑定。

For now I've found a better solution and that's to use NinjectModule. In the Plugin class, I'm going to create a class which inherits from NinjectModule. Then setup the pluging bindings in the Load overload.

然后使用Kernel.Load在我的主要的应用程序引导程序,其中从NinjectModule继承所有插件类初始化负载过载。

Then use Kernel.Load in my main app bootstrapper to initialize the Load overloads in all plugin classes which inherit from NinjectModule.

这篇关于MVC Ninject:如何从一个MVC区项目中添加NinJect绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆