具有实体框架的WCF存储库服务模式

时间:2010-07-22 18:24:32

标签: c# wcf entity-framework architecture

我需要在silverlight,asp.net等中使用表示层,所以一切都是通过wcf服务。 我对存储库层,服务层,wcf服务的实现有很多疑问

我目前正在做的事情

  1. 我有存储库,它不是每个表根据聚合根创建的
  2. 我有服务层用于执行涉及多个存储库的一组操作
  3. WCF服务将方法包装在服务层和存储库层
  4. 实体由EF自动生成
  5. 传递实体并将其作为完整图形
  6. 返回到服务层

    6.我有两个具有所有存储库的具体类,以及名为repositorycontainer和service container的服务,将存储库容器传递给服务

    我的存储库

    public class RepositoryBase
        {
            public DataBaseContext _Context;
            public RepositoryContainer _RepositoryContainer;
            public RepositoryBase(RepositoryContainer repositoryContainer)
            {
                _RepositoryContainer = repositoryContainer;
                _Context = repositoryContainer.Context;
            }
            public RepositoryBase()
            {
                _RepositoryContainer = new RepositoryContainer();
                _Context = _RepositoryContainer.Context;
            }
    
    
        }
    

    我的存储库容器

    public class RepositoryContainer
        {
            public RepositoryContainer()
            {
                Context = new DataBaseContext();
            }
            public RepositoryContainer(DataBaseContext context)
            {
                Context = context;
            }
     public DataBaseContext Context
        {
            get;
            set;
        }
    
    
            public SurveyRepository _SurveyRepository;
            public SurveyRepository SurveyRepository
            {
                get
                {
                    return _SurveyRepository ?? (_SurveyRepository = new SurveyRepository(this));
                }           
            }
    
    
    }
    

    我的服务容器

     public class ServiceContainer
        {
            public ServiceContainer()
            {
                RepositoryContainer = new RepositoryContainer();
            }
            public ServiceContainer(RepositoryContainer container)
            {
                RepositoryContainer = container;
            }
    
    
            public RepositoryContainer RepositoryContainer
            {
                get;
                set;
            }
       public SurveyService _SurveyService;
            public SurveyService SurveyService 
            {
                get
                {
                    return _SurveyService?? (_SurveyService= new SurveyService(this));
                }           
            }
    
    
        }
    

    进行手术 我只是创建RepositoryContainer或ServiceContainer

    然后调用

    RepositoryContainer.Repository.Method()
    ServiceContainer.Service.Method()
    

    我怀疑是

    1. 该服务/存储库容器是否正常?

    2. 我已经有了服务层,因为我有wcf服务,我称之为当前的服务层servicewrapper或其他东西?

    3. 我需要调用存储库方法本身,例如:GetCategory()等,也是服务层中的所有方法,所以我需要在wcf服务中包装方法和服务,是不是很好?

    4. 在哪里进行缓存?因为我正在使用EF,我认为有一些方法可以使用带有EF的缓存提供程序,

1 个答案:

答案 0 :(得分:3)

相关问题