Migrating from Unity to Simple Injector

May 31, 2014 at 7:02 AM
Edited May 31, 2014 at 7: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;
CurrentControl.SelectedItem=SelectedItem;
CurrentControl.Activity=Activity;
HttpContext.Current.Application.GetContainer().BuildUp(CurrentControl.GetType(), CurrentControl, CurrentControl.ID);
Coordinator
May 31, 2014 at 7: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);
producer.Registration.InitializeInstance(page);
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 9:22 AM
Edited May 31, 2014 at 10: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 11:41 AM
What would be the equivalence of Unit Resolve method in Simple Injector.
UnityContainer.Resolve<IDataContext>();
Coordinator
May 31, 2014 at 11:53 AM
That would be The GetInstance<T> method:
container.GetInstance<IDataContext>();