让 SNAP(AOP)、NInject 和 ASP.Net MVC 3 协同工作 [英] Getting SNAP(AOP), NInject and ASP.Net MVC 3 working together

查看:27
本文介绍了让 SNAP(AOP)、NInject 和 ASP.Net MVC 3 协同工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人让 SNAP AOP 框架与 MVC 3 和 Ninject 一起工作.

Has anyone got the SNAP AOP framework working with MVC 3 and Ninject.

使用 NuGet 添加 Snap 到 MVC 3 项目时给出的示例不适用于之前添加的 NInject 包.我试图根据正常的 NInject 方法让它工作,但无法让它真正拦截!

The samples given when adding Snap using NuGet to an MVC 3 project don't specifcally work well with a previously added NInject package. I have tried to get it working based on the normal NInject approach but just cannot get it to actually intercept!

谁能在代码中展示如何做到这一点?

Can anyone show how to do this in code please?

推荐答案

我通过 NuGet 使用最新版本的 Ninject 解决了这个问题,Ninject 现在在 MVC3 应用程序的新 AppStart 文件夹中添加了一个类调用 NinjectMVC3.

I figured it out with the latest version of Ninject through NuGet which now adds a class call NinjectMVC3 in a new AppStart folder in the MVC3 application.

我使用的代码如下:在自动创建的 NinjectMVC3.cs CreateKernel() 方法中:-

The code I used is as folows: In the automatically created NinjectMVC3.cs CreateKernel() method:-

         private static IKernel CreateKernel()
        {
            // Wire it up with AOP
            NinjectAopConfiguration.NinjectAopConfigure();

            //var kernel = new StandardKernel(); // Removed

            RegisterServices(NinjectAopConfiguration._container.Kernel);

            return NinjectAopConfiguration._container.Kernel;
        }

我还在 RegisterServices() 方法中为各种注入目标连接了 Ninject.

I also wired up Ninject for the various injection targets in RegisterServices() method.

接下来我拿了 NuGet 生成的示例代码,将 SNAP.Ninject 添加到 MVC 3 应用程序中,将其重命名为 NinjectAOP.cs 并使其看起来像这样:

Next I took the sample code generated by NuGet when adding SNAP.Ninject to the MVC 3 application, renamed it NinjectAOP.cs and made it look like this:

 public static class NinjectAopConfiguration
    {
        public readonly static NinjectAspectContainer _container;

我还需要为 Ninject 执行程序集绑定重定向,如下所示,因为 Ninject 在某处存在程序集版本冲突:

I also needed to do an assembly binding redirect for Ninject as follows because there is an assembly version conflict somewhere for Ninject:

我希望这对某人有所帮助.

I hope this helps someone.

我邀请任何人看看他们是否可以改进这一点.

I invite anyone to have a look and see if they can improve this please.

这篇关于让 SNAP(AOP)、NInject 和 ASP.Net MVC 3 协同工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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