I use the FactorySupportFacility, in conjucntion with GenericFactory, and
register this:
var engineContextFactory = new GenericFactory<IEngineContext>(() =>
MonoRailHttpHandlerFactory.CurrentEngineContext);
var engineContextFactoryName = engineContextFactory.GetType().FullName;
container.Register(Component.For<GenericFactory<IEngineContext>>()
.Instance(engineContextFactory)
.Named(engineContextFactoryName),
Component.For<IEngineContext>()
.Attribute("factoryId").Eq(engineContextFactoryName)
.Attribute("factoryCreate").Eq("Create")
.LifeStyle.Transient);
A subdependency resolver fir IEngineContext is a very good idea.
As for your problem - I think it has nothing to do with MR ot windsor.
On app start, the Session object might simply not be available.
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jason Meckley
Sent: Tuesday, February 24, 2009 4:53 PM
To: Castle Project Users
Subject: Register IEngineContext in Kernel
I have a simple service which loads users specific data into session on
session start.
if I place this code in the global.asax session_start member it loads fine.
abstracting this away from the http context. I created a UserStartUp service
which takes IEngineContext and IUserRepository as ctor args.
I then created a sub dependency resolver to resolve the context engine.
which is basically an adapter around
MonorailHttpHandlerFactory.CurrentEngineContext.
however when my application starts I get an null reference exception at
context.Session[key] = value;
the context is created, but session is null.
I call the UserStartUp service in
Global : HttpAppliation
{
public void Session_Start(...)
{
Container.Resolve<IUserStartUp>().start();
}
}
[Transient]
UserStartUp : IUserStartUp
{
//ctor args
public void start()
{
var id = context.CurrentUser.Identity.Name;
context.Session[key] = repository.get(id).name;
}
}
again, if the code is placed directly in the Session_Start member it works.
however if I move the code into a service and call the service from
Session_Start, session is null.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---