【发布时间】:2009-05-19 17:14:22
【问题描述】:
如果我有这样的服务定义/实现:
using System;
using System.ServiceModel;
namespace aspace.service
{
[ServiceContract(Namespace = "http://aspace.service")]
public interface IUpdate
{
[OperationContract]
ConfirmationMessage UpdatePerson(string PersonIdentifier);
}
}
public class UpdateService : IUpdate
{
public ConfirmationMessage UpdatePerson(string PersonIdentifier)
{
// some implementation here
}
}
我可以像这样创建一个服务主机:
ServiceHost host = new ServiceHost(typeof(UpdateService), someEndpointAddress);
然后,在创建绑定并添加元数据行为之后,我可以打开主机。它将根据客户的请求调用 UpdatePerson(aPersonIdentifier)。
我想与 UpdatePerson 的数据库交谈。 a previous question of mine 的答案建议我应该对这类事情使用依赖注入。
问题是我从未创建类 UpdateService 的实例。那么如何注入依赖项呢?你会如何解决这个问题?
谢谢,问候,米尔。
【问题讨论】:
标签: c# wcf dependency-injection