我有一個在windows服務中託管的wcf服務庫。我需要攔截撥打 服務方式的電話。對於這種情況,建議到WCF註冊到Unity容器,可以在這個環節可以看出在Unity容器中註冊WCF服務
http://weblogs.asp.net/fabio/archive/2009/03/24/inversion-of-control-with-wcf-and-unity.aspx
我想實現從Codeplex.I Unity.WCF裝配了類似的做法無法理解在哪裏把我的容器配置或引導程序放在wcf服務庫(或windows服務)中。沒有提供可靠的樣本(vs解決方案)。
我的Windows服務主機
private UnityServiceHost _serviceHost = null; private readonly UnityContainer _container;
public Service() {
InitializeComponent();
_container = new UnityContainer();
_container.AddNewExtension<Interception>();
_container.RegisterType<ISecurityRepository, SecurityRepository>();
_container.Configure<Interception>().SetDefaultInterceptorFor<ISecurityRepository>(new TransparentProxyInterceptor());
}
protected override void OnStart(string[] args) {
//SecurityService
if (_serviceHost != null) {
_serviceHost.Close();
} else {
_serviceHost = new UnityServiceHost(_container, typeof(SecurityRepository));
_serviceHost.Open();
}
}
protected override void OnStop() {
//SecurityService
if (_serviceHost != null) {
_serviceHost.Close();
_serviceHost = null;
}
}
我的服務合同
[的ServiceContract(SessionMode = SessionMode.Required)] 公共接口ISecurityRepository {
[OperationContract(IsInitiating = true)]
IList<vNavigationTree> GetNavigationTree(string ticket);
[OperationContract(IsInitiating = true)]
string GetSessionGuid(string userName, string IP, string machineName);
}
在這種情況下,它似乎攔截不work.Briefly什麼我需要的是一個示例項目,其中WCF服務已註冊到DI容器,並且服務方法被攔截。