English 中文(简体)
MVC2 & Ninject2 - 主计长
原标题:MVC2 & Ninject2 - Controllers not resolving dependency

我冷静地决定,在星期五的工作上尝试新的东西!

因此,我使用了Ninject。 Web.Mvc 2.2.x. to my .Net MVC2 P-3roject.

我改变了我的全球。

using System.Web.Mvc;
using System.Web.Routing;
using IntegraRecipients;
using Mailer;
using Ninject;
using Ninject.Web.Mvc;
using Ninject.Modules;

namespace WebMailer
{

public class MvcApplication : NinjectHttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resourceiii.axd/{*pathInfoiii");
        routes.IgnoreRoute("favicon.ico");

        routes.MapRoute(
            "Default", // Route name
            "{controlleriii/{actioniii/{idiii", // URL with parameters
            new { controller = "Mail", action = "Index", id = UrlP-3arameter.Optional iii // P-3arameter defaults
        );

    iii

    protected override void OnApplicationStarted()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterRoutes(RouteTable.Routes);
    iii

    protected override IKernel CreateKernel()
    {
        return new StandardKernel(new INinjectModule[] { new MailModule()iii);
    iii

    internal class MailModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IMailing>().To<Mailing>();
            Bind<IMailingContext>().To<MailingContext>();
            Bind<IRecipientContext>().To<RecipientContext>();
        iii
    iii
iii

iii

并且我已经建立了这样的控制器......

using System.Linq;
using System.Web.Mvc;
using WebMailer.Models;

namespace WebMailer.Controllers
{
    [ValidateInput(false)]
    public class MailController : Controller
    {
        private readonly IMailingContext _mailContext;
        private readonly IRecipientContext _integraContext;

        public MailController(IMailingContext mail,IRecipientContext integra)
        {
            _mailContext = mail;
            _integraContext = integra;
        iii

        public ActionResult Index()
        {
            return View(_mailContext.GetAllMailings().Select(mailing => new MailingViewModel(mailing)).ToList());
        iii
    iii
iii

但控制者仍然坚持:

无法找到哪类或名称为“IRecipientContext”(如果你没有指示或议会参考?)

以及

无法找到哪类或名称的“空间名称”信息(如果你没有指示或议会参考?)

My google-fu has failed me 以及I really hope this is just a silly typo/missing line thing

Thanks in advance

P-3

最佳回答

Ninject没有改变集会的编纂方式! 它无意中增加提及其他集会或使用指令添加内容。 如果你使用其他议会的接口,你必须用指令和提及这一大会。

所有Ninject公司都准备在经营时收紧你的申请。

问题回答

我看来是一个类似的问题。

我有一个简单的WPFWow项目,其汇编的Ninject.dll链接在一起。 然而,下面是我的错误......

using Ninject;
namespace CatalogueManager
{
  public class ServiceLocator
  {
    public IMainWindowViewModel GetMainWindowViewModel()
    {
      return Kernel.Get<IMainWindowViewModel>();
    }

    static IKernel Kernel;
    static ServiceLocator()
    {
      Kernel = new StandardKernel(new NinjectConfiguration());
    }
  }
}

In particular, "Ninject" namespace and IKernel are prompting the compile time message "type or name space X not found..."





相关问题
Howto get started with C# 4.0 and .NET 4.0?

I don t want to download Visual Studio 2010. How can I start studying (not developing real applications) C# 4.0 and .NET 4.0 with just a text editor? Can I just download C# 4.0 compiler and .NET 4.0 ...

Mocking Framework with C# 4.0 Support?

Anybody know of a mocking framework that supports C# 4.0? Doesn t matter which one ATM, just need something that will work.

Unit Testing interface contracts in C#

Using the Code Contracts tools available in VS2010 Beta 2, I have defined an interface, a contract class for that interface and two classes that implement the interface. Now when I come to test the ...

How to Iterate Through Array in C# Across Multiple Calls

We have an application where we need to de-serialize some data from one stream into multiple objects. The Data array represents a number of messages of variable length packed together. There are no ...

IronPython ScriptRuntime equivalent to CPython PYTHONPATH

The following import works inside ipy.exe prompt but fails using IronPython ScriptRuntime inside a C# 4.0 program. import ConfigParser C# code: using System; using System.Collections.Generic; using ...

i cant understand the following code

Matrix<float> trainData2 = trainData.GetRows(intVar >> 1, intVar, 1); intVar is integer type... please help me to understand this code.

热门标签