This project is read-only.

Migrating from Unity to Simple Injector

May 31, 2014 at 8:02 AM
Edited May 31, 2014 at 8:15 AM
Hi there,
How can I achieve this in Simple Injector. Couldn't find a Unity BuildUp method in Simple Injector.
Let me clarify that at this step of the application I've already set up Container conifguration in Bootstrapper and Invoked GetInstance.
And yet another point worth mentioning is that I don't know type of CurrentControl . but it's Generic.

var ctl= Page.LoadControl(ResourceHelper.GetResourcePath(assembly, source));
dynamic CurrentControl = ctl;
HttpContext.Current.Application.GetContainer().BuildUp(CurrentControl.GetType(), CurrentControl, CurrentControl.ID);
May 31, 2014 at 8:47 AM
If I'm not mistaken, you are targeting Web Forms. There's an integration guide for Web Forms that explains how to do this. It also shows an example of Unity's 'BuildUp' equivalent. The way to do 'BuildUp' in Simple Injector is as follows:
var producer = container.GetRegistration(page.GetType().BaseType, true);
The Registration.InitializeInstance method allows the instance to go through part of the Simple Injector Resolve Pipeline (to be precise: it executes the Select properties, Intercept expression and Apply initializers steps for that instance).
Marked as answer by shararehl on 5/31/2014 at 2:03 AM
May 31, 2014 at 10:22 AM
Edited May 31, 2014 at 11:28 AM
Thanks. It worked. I have another question. How can I implement [Dependency] attribute in Unity using Simple injector?

Thanks I figured out the answer in integration guide for Web Forms .
Marked as answer by shararehl on 5/31/2014 at 3:28 AM
May 31, 2014 at 12:41 PM
What would be the equivalence of Unit Resolve method in Simple Injector.
May 31, 2014 at 12:53 PM
That would be The GetInstance<T> method: