I am having a WCF application hosted on IIS. I am initializing an IoC container in a custom ServiceHostFactory.
基本上,我想要能够把IoC集装箱“inject”运至在该服务公司范围内设立的各个服务机构。
你们如何做到这一点?
Ariel
I am having a WCF application hosted on IIS. I am initializing an IoC container in a custom ServiceHostFactory.
基本上,我想要能够把IoC集装箱“inject”运至在该服务公司范围内设立的各个服务机构。
你们如何做到这一点?
Ariel
和你一样,你将需要一个习俗服务机构,用于创建你的服务。 与此类似:
public class SessionPerCallServiceHostFactory : ServiceHostFactory { public SessionPerCallServiceHostFactory() { } protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { return new SessionPerCallServiceHost(serviceType, baseAddresses); } }
你们还需要一个负责创造必要服务的服务机构:
public class SessionPerCallServiceHost : ServiceHost { public SessionPerCallServiceHost() { } public SessionPerCallServiceHost(Type serviceType, params Uri[] baseAddresses) : base(serviceType, baseAddresses) { } protected override void OnOpening() { Description.Behaviors.Add(new SessionPerCallServiceBehavior()); base.OnOpening(); } }
采用惯用的ISERBehavior,能够提供用来制造服务的提供人:
public class SessionPerCallServiceBehavior : IServiceBehavior { public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) { ChannelDispatcher cd = cdb as ChannelDispatcher; if (cd != null) { foreach (EndpointDispatcher ed in cd.Endpoints) { ed.DispatchRuntime.InstanceProvider = new SessionPerCallInstanceProvider(serviceDescription.ServiceType); } } } } public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection endpoints, BindingParameterCollection bindingParameters) { } public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { } }
最后,将允许你利用国际奥委会在所请求的服务场合注入你所希望的任何东西的助手:
public class SessionPerCallInstanceProvider : IInstanceProvider { private readonly Type _serviceType; public SessionPerCallInstanceProvider(Type serviceType) { _serviceType = serviceType; } public object GetInstance(InstanceContext instanceContext, System.ServiceModel.Channels.Message message) { //I m creating it without any tricks but you could use your IoC container here return Activator.CreateInstance(_serviceType); } public object GetInstance(InstanceContext instanceContext) { return GetInstance(instanceContext, null); } public void ReleaseInstance(System.ServiceModel.InstanceContext instanceContext, object instance) { } }
希望!
In an ASP.NET web app, using Integrated Windows Authentication, is the session tied to the windows identity? In other words, if I login (using IWA) to the app, and the app stores some "stuff" in my ...
Does anyone know if I can use Elmah with Visual Studio build-in web server(aka Cassini)? I get it working easily on IIS, but using same configuration, it doesn t work with Cassini. When I requested ...
I want to set the hostname for a website I m adding in IIS 7, however do I include the www in the hostname or not? because I want both www.mysite.com and mysite.com both to point to mysite on the ...
I m developing an ASP.NET MVC site that utilizes forms authentication for part of the application. During development, I need to be able to give external parties access to a development server hosting ...
I ve run websites out of inetpub, as well as from folders just residing on the C: drive. I wonder, are there any definitive advantages to running websites out of inetputwwwroot?
I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...
The following line of PowerShell works with IIS 6 installed: $service = New-Object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC") However, with IIS 7 it throws the following error ...
Recently my ISP switched our website to an IIS7.0 high availibility cluster. The website is running on PHP5.2.1 and I can only upload files (so no registry tweaks). I had tested the website before and ...