简体   繁体   English

温莎WCF设施工厂?

[英]Windsor WCF Facility factory?

So I currently have a master DAO class ITrackingToolDAO that has all the Service Contracts for each of my business entities. 因此,我目前拥有一个主DAO类ITrackingToolDAO,该类具有我每个业务实体的所有服务合同。

public partial interface ITrackingToolDAO {
    void Open(string connectionString);
    void Close();

    IBusinessFunctionDAO BusinessFunction { get; }
    IBusinessUnitDAO BusinessUnit { get; }
    IProgramBudgetDAO ProgramBudget { get; }
    IProjectDAO Project { get; }
    ...
}

My Service Contract looks like so 我的服务合同看起来像这样

[ServiceContract(Namespace="http://bmgops.qintra.com/Tracking/v1/BusinessFunction")]
public partial interface IBusinessFunctionDAO {

    [OperationContract]
    BusinessFunction GetBusinessFunction(Int32 businessFunctionId);

    [OperationContract]
    IEnumerable<BusinessFunction> Find(string filter);

    [OperationContract]
    SaveEventArgs<BusinessFunction>Save(BusinessFunction businessFunction);
}

I currently have 2 concrete implementations of my ITrackingToolDAO interface. 我目前有2个ITrackingToolDAO接口的具体实现。 The first one is TrackingToolSqlDAO which instantiates a concrete SQL DAO for each entity. 第一个是TrackingToolSqlDAO ,它为每个实体实例化一个具体的SQL DAO。 ie) BusinessFunctionSqlDAO , ProjectSqlDAO , etc. 即) BusinessFunctionSqlDAOProjectSqlDAO等。

The second one is a TrackingToolWCFDao which creates WCF proxys using ChannelFactory<T> to create an implementation for all my DAO members. 第二个是TrackingToolWCFDao ,它使用ChannelFactory <T>创建WCF代理,以为我的所有DAO成员创建一个实现。

Now, I want to start using the Windsor WCF facility instead of CreateChannel. 现在,我想开始使用Windsor WCF工具而不是CreateChannel。 What would be the best way to accomplish this ? 做到这一点的最佳方法是什么?

I was thinking of creating a dummy implementation of ITrackingToolDAO that took in an IKernel parameter in the constructor. 我正在考虑创建ITrackingToolDAO的虚拟实现,该实现在构造函数中使用了IKernel参数。

public class DummyDAO: ITrackingToolDAO {
    public DummyDAO(IKernel kernel) {
        _ProjectDAO = kernel.Resolve<IProject>();
        ....
    }
}

This way i could use the WCF Facility to create all my channels. 这样,我可以使用WCF工具创建所有频道。 I just don't like it cuz it's using the container as a service locator which is a code smell. 我只是不喜欢它,因为它使用容器作为服务定位器,这是一种代码味道。 Ideally I would also like it if I could have my SQL DAO and new WCF DAo both registered in the container so I could create either one by just referencing them by name. 理想情况下,如果我可以将我的SQL DAO和新的WCF DAo都注册在容器中,那么我也很喜欢,因此我可以通过仅按名称引用来创建它们之一。

Any thoughts ? 有什么想法吗 ?

If you're using Castle.Facilities.WcfIntegration, you could setup your dao like this: 如果您使用的是Castle.Facilities.WcfIntegration,则可以这样设置dao:

container.Register(Component.For<IProject>().ImplementedBy<Project>());

You can than use WcfIntegration facility like this: 然后可以像这样使用WcfIntegration工具:

container.AddFacility<WcfFacility>()
    .Register(Castle.MicroKernel.Registration.Component.For<IBusinessFunctionDAO>()
    .ImplementedBy<BusinessFunctionDAO>()
    .AsWcfService());

Than for BusinessFunctionDAO you can do constructor injection like this: 比于BusinessFunctionDAO,您可以像下面这样进行构造函数注入:

public class BusinessFunctionDAO : IBusinessFunctionDAO 
{
   public BusinessFunctionDAO(IProject project)
   {
      if (project== null) new ArgumentException("project");
      _project = project;
   }
...


   private readonly IProject _project;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM