Hey all. I'm coming across a weird design pattern using the repository and service model. The application constists of ASP.NET MVC, WCF, and some Windows services. My repositories are using LINQ DataContext. As my application evolves I'm finding myself passing references to IWhateverService service everywhere. For example, I have IAccountService which defines methods such as ChangePlan(Account account, Plan plan).
Now, it seems like IAccountService is the best place to put this method since we're servicing accounts here. However, the ChangePlan method needs to know several things before it can actually change the plan. It has to know the user's current usage, the list of available plans, an instance to an ecommerce service interface for billing, etc.
I thought having ChangePlan method accept all of the required services in the IAccountService interface. But the requirement of these other services is a matter of implementation and shouldn't be part of the interface definition.
So now I find myself creating a huge constructor for AccountService taking an instance of IAccountRepository, IPlanService, IUsageService, IEcommerceService, and IValidationDictionary. This doesn't feel right at all.
Now take this scenario. Obviously IAccountService contains a simple method to retrieve a user's account by ID: Account Get(int id) There are several times when I just need to call this method only. So, I go to create my AccountService, and it wants instances of all these other services (especially IValidationDictionary, I'm not needing validation for this). Again, this feels wrong. I could pass null, but that's only becuase I know the implementation doesn't use them for just this method.
Also, to avoid instantiating the services everywhere I need them, I created a static class called ServiceFactory, which has static methods, CreateAccountService, CreatePlanService, etc... I call these methods around the application. The seems OK but I can't shake the feeling that this is improper.
Where's my disconnect here? Anyone got any suggestions?
Thanks.
Andrew