开发者

Should I minimize the number of interfaces in a controller?

开发者 https://www.devze.com 2023-02-26 02:23 出处:网络
In the below snip I have my controller which takes three interfaces. These are wired up via Ninject. Ok all great, definately a step in the right direction. My questions are this?

In the below snip I have my controller which takes three interfaces. These are wired up via Ninject. Ok all great, definately a step in the right direction. My questions are this?

1.) Would it be better to wrap the 3 interfaces up in to one interface and a implement that way, thus reducing the amount of params passed to the ctor of the controller? 2.) Leave it alone开发者_StackOverflow社区, it is working?

I am always looking for ways to abstract the hell out of everything.. Thoughts?

public class RegistrationController : Controller
{
    private readonly ICategoriesService _categoriesService;
    private readonly IAuthenticationService _authenticationService;
    private readonly IRegistrationService _registrationService;

    // Ctor
    public RegistrationController(ICategoriesService categoriesService, 
        IAuthenticationService authenticationService,
        IRegistrationService registrationService)
    {
        _categoriesService = categoriesService;
        _authenticationService = authenticationService;
        _registrationService = registrationService;
    }

}


Having a huge interface (or a huge class, which is what you'll need in order to implement a huge interface) because it is "convenient" is widely considered an antipattern. Based on the names of your current interfaces, they seem to be nicely and logically structured around what kind of operations they provide, and I suggest that you keep them that way (this also gives higher flexibility, since there may be other places where you only need some of the interfaces).

By the way: If you have proper unit tests and integration tests, "leave it alone, it's working" is a phrase that is never needed. ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号