问题描述
我有一个使用NHibernate和温莎城堡的IoC的一个ASP.NET MVC应用程序1。该控制器具有服务类注入,而这些服务类处理所有的逻辑和应用程序所需的操作。服务类有注射库。每个库处理一个对象。对象映射通过NH db表的。我试图保持一个服务和控制器之间的一个关系,但是有些服务是在一个以上的控制器中使用。
I have an ASP.NET MVC 1 application that uses NHibernate and Castle Windsor for IoC. The controllers have service classes injected, and these service classes handle all the logic and actions required by the app. The service classes have repositories injected. Each repository handles a single object. Objects are mapped to DB table via NH. I have tried to keep a one to one relationship between services and controllers, but some services are used in more than one controller.
的问题是,一些服务现在有10-15库的依赖关系。该系统具有例如开票成分,其中某些行为取决于用户,客户,工作单,工作订单行项目,发票,发票行项目,税收等。
The problem is that some services now have dependencies on 10-15 repositories. The system has an invoicing component for example, where certain actions depend on users, customers, work orders, work order line items, invoices, invoice line items, taxes, etc.
中,人们采用什么策略有效地重构,当谈到扶养超载?我想分裂一个服务为许多服务和删除服务和控制器之间的1对1的尝试。但随后依赖在控制器级别将增加。拆分一个控制器到多个控制器,可以与现有的建议,但我不相信,除非你打破意见纳入局部视图这样做了?我意识到这是一个广泛的问题,但我更希望比确切的答案指导。随意提供文章链接或类似的重构的例子。
What strategies do people used to refactor effectively when it comes to dependency overload? I'm thinking of splitting one service into many services and to remove the 1-to-1 attempt between services and controllers. But then dependencies at the controller level will increase. Splitting one controller into many controllers is possible with the prior suggestion, but I don't believe that's done unless you break views into partial views? I realize this is a broad question, but I'm more looking for guidance than exact answers. Feel free to provide links to articles or examples of similar refactoring.
推荐答案
您应该,其中涉及在编排的细粒度的服务更粗粒度的服务一个新层滑动。目前您的控制器是做得太多细粒度的工作。
You should refactor to Facade Services, which involves sliding in a new layer of more coarse-grained services that orchestrate the finer-grained services. Currently your Controllers are doing too much fine-grained work.
包含此过程的一个例子,它也触及了一些你可以做鉴定服务的适当的集群心理练习进行分组。
FWIW chapter 6 of my book contains an example of this process and it also touches on some of the mental exercises you can do to identify the appropriate clusters of services to be grouped.
请注意,一个特定的服务可以是一个以上的集群的成员。这基本上只是表明这是在应用程序中的核心服务。
Keep in mind that a particular service can be a member of more than one cluster. That basically just indicates that this is a central service in the application.
这篇关于战略重构,当太多的依赖注入的服务或控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!