views:

83

answers:

1

I have successfully setup castle windsor using an xml configuration file and everything works fine. The only problem is that on a method I need Windsor to pass an existing instance to the constructor so I used

container.Kernel.AddComponentInstance<IMyClass>(MyClassInstance);

before the Resolve method but that does not work because Windsor creates an new instance of IMyClass based on the xml config file. That behavior if fine on every other place except this particular method that I need to pass the existing instance. How can I solve that problem. Tried to find documentation on the web but no luck until now :(.

A: 

You can do this:

var instance = new MyClass();
container.Register(Component.For<IMyClass>().Instance(instance));
Mark Seemann
Didn't work well for me. I want to handle the nhibernate session .. and I want to pass an SQLite session when testing (manually instantiated) else I want mapped session by the xml config file. But its even more complicated because I want to break my data layer to more tha one logical modules and assemblies so I have to refactor even more because now I have two session factories one for each data module so I use parameters (on the windsor xml config) for classes needed. Thanx anyway u gave me one more good way to experiment.
George Statis