windows - asp.net mvc with ioc --> avoiding constructor soup with BaseController -
I have a base controller that uses I'm using to house my cross cutting concerns for an MVC project .
However, this means that 3 dependencies of my controller:
public base controller (IUserService u, ITenantDetailsService t, ISiteConfiguration c)
this is the side effects that are awash with my constructors standards for each derivative controller:
public AccountController (ILocationService locationService, IAccountService accountService, IFormsAuthentication formsAuth, IMembershipService service, IUserService userService , ISiteConfiguration configuration): Base (locationService, userService, Configuration)
I To solve the mechanisms I am using IoC (Windsor), so I know that I can remove manufacturer dependencies and it can automatically pass on public properties.
Is there any reason to do this except for some dependency masking?
Public Account Controller (IAccountService, IFormsAuthentication, IMembershipService)
This approach is much more readable and gives a clear overview of the dependencies related to that particular controller.
Or is it all wrong and bascontroller is not the right place to store cross-cutting services.
Appreciated the ideas.
Thanks, Chris
is a cause about which I'd imagine Conference - Many people have the means of bearing dependency and setter injection as manufacturer injection according to the requirement. Etiof - this is just a conference, and I can not stop myself from using auto-wired properties in this example. Dependent injection is considered to make your work easier (I think it is not the most important reason to use DI, but I think this is a legitimate reason) to consider such a situation. when you need to add another "global" service have to go through every controller in your project and is a manufacturer, which is really too bad, would be to modify
I this To solve the problem came up with another idea. To make a collector object, that stores all "global" dependencies, converting it to concrete controllers, then the base was passed, which will receive the necessary dependencies, it will solve the problem in adding dependency and you will clearly tell it clearly That the concrete controller is passing dependency for the base class. I did not like it though, because it still requires 2 classes ("dependency collector" and baseController) to change when I add new, "global" dependency.
Comments
Post a Comment