我冷静地决定,在星期五的工作上尝试新的东西!
因此,我使用了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