lundi 3 août 2020

Mimic pipeline DI for controllers in integration testing DI for the same controllers

I have a large, complex project whose core architecture is still relatively unknown to me. I have several module projects, one controller, models and views per project. I also have a DAL with a service class for each model. Every controller has many different dependencies on these DAL services and does not use constructor injection for them. These are declared as 'instances' of interfaces in the controllers, but they are not attributed for property injection; they are resolved by a

UnityConfig.InjectFields(this);

call in the ctor of the BaseConstroller, that instantiates them with instances resolved by the active Unity container. UnityConfig contains a Lazy (singleton) instance of the one unity container. Dependency registration takes place in a (for one project/controller) ProjectAuthorityModuleRegistration class, in classic container.RegisterType style.

Now I would like to use my own Unity container for the tests, but I would still like to use the base controller's resolution of dependencies, as well as the <propjectName>ModuleRegistration class. Changes to non-test code should not occur, as this would mean always changing code under test instead of changing the test code.

I am looking for ways to use my own container but call e.g the ProjectAuthorityModuleRegistration class to register all a controller's dependencies, and also call the InjectFields method, but have both these methods use my own container, that can take the place of the MVC pipeline's container configured in the project under test. I can change BaseController (carefully), and I can change the UnityConfig.InjectFields method and other methods on that class. I cannot change the <propjectName>ModuleRegistration class or the controllers.

All suggestions and input are welcome.

Aucun commentaire:

Enregistrer un commentaire