我的项目架构类似于Droid,
Data access layer Droid项目-> ->项目。
现在,如果我想直接访问Droid项目中数据访问层的任何方法,我需要将数据访问层的引用添加到Droid项目中。
有没有什么方法可以访问DAL to Droid poject的方法而不将其添加为引用文件?
发布于 2017-10-04 01:51:26
我认为最好的办法是引入一个位于PCL内部的服务层
如果需要的话,您的服务层应该能够处理多个存储库,并且您还有一个额外的好处,那就是拥有一个与DAL对话的服务和另一个与您的API对话的服务,两者都使用相同的接口。
// DAL
public class SomeRepository : ISomeRepository
{
public void DoSomething(){
// do something
}
}// PCL
public interface ISomeRepository
{
void DoSomething();
}
public interface ISomeService
{
void DoThings();
}
public class SomeService : ISomeService
{
private ISomeRepository _someRepository;
SomeService(ISomeRepository someRepository)
{
_someRepository = someRepository;
}
public void DoThings()
{
// do things via DAL
}
}
public class SomeProxyService : ISomeService
{
private HttpClient _httpClient;
SomeProxyService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public void DoThings()
{
// do things via HTTP
}
}https://stackoverflow.com/questions/46550424
复制相似问题