Question

Issue

I am using Castle Windsor as an IoC container in a Castle Monorail project. I would like to inject the current instance of IRailsEngineContext into an object being resolved from the container in a controller.

Context

The object I would like inject the rails context into would be used to wrap the session object for the purpose of retaining the ids of previously viewed records. It would then be referenced to ensure that they aren't viewed again.

Alternate Solutions

I could pass the context to the methods with each call or inject it manually, but it would be nice to inject it directly from the container.

Question

I can't think of a way to inject the context within the container. Is there a way to do this? Does this even make sense?

Was it helpful?

Solution

Container.Register(
    Component.For<IRailsEngineContext>()
             .UsingFactoryMethod(()=>MonoRailHttpHandler.CurrentContext)
             .LifeStyle.Transient
);

IRailsEngineContext - that's from an old version of MonoRail I guess. I'd advise you move to a newer one, the sooner the better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top