6
其中第一种获取客户数据的方法有哪些优势?服务与存储库
ICustomerService customerService = MyService.GetService<ICustomerService>();
ICustomerList customerList = customerService.GetCustomers();
与
ICustomerRepository customerRepo = new CustomerRepository();
ICustomerList customerList = customerRepo.GetCustomers();
如果你明白我的问题,你会不会问的MyService类的实现看起来像;-)
这里是回购的实施.. 。
interface ICustomerRepository
{
ICustomerList GetCustomers();
}
class CustomerRepository : ICustomerRepository
{
public ICustomerList GetCustomers()
{...}
}
@Jamie 或LightCore http://lightcore.peterbucher.ch/ ;-) 好对于具有10k LoC的桌面应用程序,我不想使用DI工具也Lightcore是该死的小;-) 你可以告诉我这种ServiceLocator的典型实现?我猜MyService是一个静态类吗? – msfanboy 2010-07-05 18:25:32
啊...所以最后我会有20个其他的如果运行20个不同的服务?地狱这就像编码vb:P btw。如果你对更多的点感兴趣:P http://stackoverflow.com/questions/3181522/c-services-access-the-dataprovider-class-running-the-sql-statements-correct-a – msfanboy 2010-07-05 18:45:50
我认为有这个模式的好实现,但这是我见过的(并且自己写的)。 – 2010-07-05 18:49:29