界面和外观设计模式
我一直在使用立面设计模式将所有行政管理组合在一起 我的程序中需要的功能。
在我的类库 Company.Infrastruct.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)。
为了实现访问,我一直在我的域逻辑中包含我的存储库类的接口。然而,我不太确定如何创建一个外观接口,例如我拥有的接口(带有子类和所有)。这可能吗?
我该怎么做?
I have been using a facade design pattern to group together all the administrative
funcionality I need in my program.
in my class library Company.Infrastructure.Repositories.Administration I have:
[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...
}
This has worked well for me. However, we have moved to a DDD model and I am trying to figure out how to continue to access my AdminRepository (formerly AdminFactory) from a WCF service.
To achieve access, I have been including the Interfaces to my Repository classes in my Domain logic. However, I am not quite sure how to go about creating an Interface to a Facade such as the one I have (with subclasses and all). Is this possible?
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很困惑为什么您想要为包含嵌套类的
AdminRepository
创建一个接口。根据您的代码,我认为您此时会指定合同,为什么合同还指定实现(在您的情况下是受保护的嵌套类)?
请注意,这并不意味着我理解您对受保护嵌套类的使用,或者为什么当所有抽象组件实际上都是内部实现时您将其称为“外观模式”,或者为什么迁移到 DDD 模型会导致访问您的存储库来自WCF的努力。但是,我当然不明白为什么您会尝试在接口中指定嵌套类,但 C# 在任何情况下都不允许这样做(请注意,VB 确实允许接口中的嵌套类型)。如果您希望以这种方式指定契约,则可以使用不带实现的抽象类而不是接口,但这会产生继承问题。
I'm confused as to why you would want to create an interface to your
AdminRepository
that includes nested classes . Based on your code, I would think you would haveAt this point, your
IAdminRepository
specifies the contract, why would the contract also specify the implementation (in your case protected nested classes) ?Note that this doesn't mean that I understand your usage of the protected nested classes, or why you call it the "facade pattern" when all of the abstracted components are actually internal implementation, or why moving to a DDD model makes accessing your repository from WCF hard. However, I certainly don't see why you'd try to specify nested classes in an interface, but c# does not allow it in any case (note that VB does allow nested types in interfaces). If you wish to specify contracts this way, you can use abstract classes without implementation instead of an interface, but this creates inheritance issues.