我一直在使用外观设计模式将程序中需要的所有管理功能组合在一起。
在我的类库 Company.Infrastructure.Repositories.Administration 我有:
[Pluggable("Default")]
public class AdminRepository : IAdminRepository
{
#region private members
#endregion
#region protected members
protected Membership _membership;
protected Permissions _permissions;
protected Application _application;
protected Profile _profile;
#endregion
public AdminRepository()
{
_membership = new Membership();
_permissions = new Permissions();
_application = new Application();
_profile = new Profile();
}
protected class Profile
{
public Profile() {}
public void ProfileMethod1(){}
public void ProfileMethod2(){}
}
protected class Membership
{
public Membership() {}
public User GetUser(Guid id)
{
using (var dc = new My_SdbDataContext())
{
var user = dc.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
var membership = dc.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
return Convert.ToEntity(user, membership);
}
}
public User GetUser(string userName)
{
using (var dc = new My_SdbDataContext())
{
var user = dc.aspnet_Users.Where(x => x.UserName == userName).FirstOrDefault();
var membership = dc.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault();
return Convert.ToEntity(user, membership);
}
}
public IEnumerable<User> GetUsers(Guid applicationId)
{
var userList = new List<User>();
using (var dc = new My_SdbDataContext())
{
var users = dc.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>();
userList.AddRange((IEnumerable<User>) (from user in users
let membership = dc.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault()
select Convert.ToEntity(user, membership)));
}
return userList;
}
}
etc...
}
这对我来说效果很好。但是,我们已经转移到 DDD 模型,我正试图弄清楚如何继续从 WCF 服务访问我的 AdminRepository(以前称为 AdminFactory)。
为了实现访问,我一直在我的域逻辑中包含我的存储库类的接口。但是,我不太确定如何创建一个到 Facade 的接口,例如我拥有的一个(带有子类和所有)。这可能吗?
我该怎么做呢?