ASP.NET MVC - Using Ninject bindings outside of controllers?

The current development release found on teamcity.codebetter.com provides support for side a side usage of ordinary aspx pages, mvc and wcf. You might want to have a look at this.

The current development release found on teamcity.codebetter.com provides support for side a side usage of ordinary aspx pages, mvc and wcf. You might want to have a look at this. Be aware this is a development version and it is not tested very well.

Nevertheless, I think it should be pretty much stable. But as it is work in progress it the interface can change. Also I won't give a lot of support before I have written the Ninject 2.4 preview blog about this change.

You need Ninject Ninject.Web. Common Ninject. Web Ninject.Web.

MVC3.

Ah, thanks for the info, I'll check this out. Does this "just work" with the MVC-defined kernel, and how do I get a handle on it from a web page? – Matt Roberts Mar 28 at 15:42 You don't need to access the kernel.It injects ordinary webpages and controls.

But you have to use property injection for them. – Remo Gloor Mar 28 at 16:06 Thats great thanks - I think I'll wait for 2.4 and then grab it from there, I can wait for this. – Matt Roberts Mar 29 at 11:35.

I've used the Ninject MVC Extension within my ASP. NET MVC application. Here is the manner in which I've achieved what I think you're trying to accomplish.Global.asax.Cs: public class MvcApplication : NinjectHttpApplication { /// /// Overridden Ninject method that is called once the application has started and is initialized /// protected override void OnApplicationStarted() { AreaRegistration.

RegisterAllAreas(); RegisterRoutes(RouteTable. Routes); // Tell the MVC Framework to use our implementation of metadataprovider. ModelMetadataProviders.

Current = new XXX.myNamespace. MetadataProvider(); // Tell the MVC Framework to use our CartModelBinder class ModelBinders.Binders. Add(typeof(Cart), new CartModelBinder()); } /// /// Establish a reference to our DIFactory object /// /// This application currently uses Ninject for dependency injection.

/// /// /// protected override IKernel CreateKernel() { return DIFactory. GetNinjectFactory(); } // snip... additional global.asax.Cs methods } DIFactory. Cs: /// /// This class is used as a container for dependency injection throughout the entire application /// public class DIFactory { public static IKernel _kernel = null; /// /// Method used to create a single instance of Ninject's IKernel /// /// IKernel public static IKernel GetNinjectFactory() { if (_kernel == null) { var modules = new INinjectModule { new ServiceModule() }; _kernel = new StandardKernel(modules); } return _kernel; } /// /// Method used as a service locator for the IConfiguration interface /// /// public static IConfiguration CreateConfigurationType() { return _kernel.Get(); } // snip....additional public static methods for all other Interafaces necessary } ServiceModule.

Cs: /// /// Configures how abstract service types are mapped to concrete implementations /// internal class ServiceModule : NinjectModule { public override void Load() { Bind().To(); // snip... all other bindings to interfaces } } Use in other classes besides Controllers: UserInteraction.Cs: public class UserInteraction : IUserInteraction { private IConfiguration configuration; public bool SubmitFeedback(Feedback feedback) { try { this. Configuration = DIFactory. CreateConfigurationType(); // snip additional logic... } catch(Exception ex) { // snip } } }.

I've used the Ninject MVC Extension within my ASP.NET MVC application.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions