ab_732
ab_732

Reputation: 3897

ASP.NET MVC 3 + Unity injection of the Controller

Which event is the best for registering the types with Unity?

I wish to do this

        iocContainer.RegisterType<ControllerA>();
        iocContainer.RegisterType<ControllerB>();

so they could be retrieved by the ControllerFactory from the Unity Container.

My opinion was to do that in the Application_Start event, but I've been warned that I could face many problems caused by the App pool recycling (not firing the Application_start). So the alternative would be the Session_start.

Any advice?

[UPDATE]

But if I use

iocContainer.RegisterInstance<IService>(service)

what happens if the app pool recycle or IIS is resetted? Is the instance of service been recreated?

Upvotes: 1

Views: 852

Answers (2)

Mark Seemann
Mark Seemann

Reputation: 233150

No, Application_start is the correct place to do it.


Nothing's going to help if the app pool or IIS (or the server is recycled). Then the container will be recycled itself, but when the app pool is restarted, the container will be configured anew.

Upvotes: 2

Related Questions