Resolve externally created object instance with no public constructor?

I was close with the container.Resolve() idea, but the final answer is simply to use the ResolvedParameter class when configuring the property to be injected using the InjectionProperty class: new InjectionProperty( "MyTarget", new ResolvedParameter())) So the calling code would look as follow: Adaptee adaptee = Adaptee.New(); adaptee. MyProperty = 5; using (UnityContainer container = new UnityContainer()) { container . RegisterType( new InjectionProperty( "MyTarget", new ResolvedParameter())); container.

RegisterInstance(adaptee, new ExternallyControlledLifetimeManager()); MyTestClass myTestClass = container.Resolve(); } I found the solution in the following post: Setter / property injection in Unity without attributes Hope this helps someboby else.

I was close with the container.Resolve() idea, but the final answer is simply to use the ResolvedParameter class when configuring the property to be injected using the InjectionProperty class: new InjectionProperty( "MyTarget", new ResolvedParameter())); So the calling code would look as follow: Adaptee adaptee = Adaptee.New(); adaptee. MyProperty = 5; using (UnityContainer container = new UnityContainer()) { container . RegisterType( new InjectionProperty( "MyTarget", new ResolvedParameter())); container.

RegisterInstance(adaptee, new ExternallyControlledLifetimeManager()); MyTestClass myTestClass = container.Resolve(); } I found the solution in the following post: Setter / property injection in Unity without attributes Hope this helps someboby else.

That was a Doh! Moment. The solution is to add the following when configuring unity: .RegisterType() I can't believe I missed that, such a simple solution which solves the problem (I think).

So te MyTarget property on the MyTestClass will resolve to a instance of the Adapter since it inherits from Target. The Adapter will obviously be initiated with the externally created instance of the Adaptee class.

So it's a double Doh! Moment. The above code works, but it is not necessarily ideal.

The Target type should not always resolve to the Adapter type, in this case it should only resolve to Adapter when injection happens for the MyTarget property in MyTestClass. – Schalk Apr 3 '09 at 6:00.

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