Question

I want to use Ninject 2 on Castle Monorail. Searching on google, I found nothing about this.

I know there is Windsor which magically can integrate with Monorail, same as Ninject (with MVC extension) with ASP.NET MVC.

What steps I need to do to integrate DI framework (other than Windsor) with Monorail ? (any website link, tutorial, or code sample (preferably using Ninject 2))

fyi, I'm using C#

Était-ce utile?

La solution

I don't think there's any documentation about this, but it's quite simple really. There's no magic to it. Since MonoRail and Windsor are completely separate projects, all you have to do is see how they integrate, then do the same for Ninject instead of Windsor.

More concretely, start with the MonoRailFacility which is the root of the integration. Instead of a Windsor facility, you'd use a Ninject module. Note it registers some components: IControllerTree, IWizardPageFactory, etc. The most important is IControllerFactory, which lets you resolve controllers from the container (in your case Ninject). You can leave all others as default for now (e.g. IFilterFactory/DefaultFilterFactory), and implement them as needed (i.e. when you need container control of filters).

Then call ServiceProviderLocator.Instance.AddLocatorStrategy(new NinjectAccessorStrategy()); where NinjectAccessorStrategy is an implementation of IAccessorStrategy which returns the Ninject kernel as a Castle.Core.IServiceProviderEx (which is nothing but a trivial extension of System.IServiceProvider). Since the Ninject kernel already implements IServiceProvider, it's trivial to write an adapter for IServiceProviderEx.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top