-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from paulomorgado/features/servicemodel
Improvements on service behavior
- Loading branch information
Showing
4 changed files
with
54 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
....Extensions.ServiceModel/DependencyInjection/SystemWebHostDependencyInjectionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Channels; | ||
using System.ServiceModel.Description; | ||
using System.ServiceModel.Dispatcher; | ||
|
||
namespace Microsoft.Extensions.ServiceModel.DependencyInjection | ||
{ | ||
[System.AttributeUsage(System.AttributeTargets.Class)] | ||
public sealed class SystemWebHostDependencyInjectionAttribute : Attribute, IServiceBehavior | ||
{ | ||
void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) | ||
{ | ||
var myIndex = serviceDescription.Behaviors.IndexOf(this); | ||
if (myIndex != (serviceDescription.Behaviors.Count - 1)) | ||
{ | ||
// Move this behavior to the end. | ||
serviceDescription.Behaviors.RemoveAt(myIndex); | ||
serviceDescription.Behaviors.Add(this); | ||
|
||
// As we've shifted everything down, the behavior at serviceDescription.Behaviors[myIndex] won't have Validate called. So, do that. | ||
serviceDescription.Behaviors[myIndex].Validate(serviceDescription, serviceHostBase); | ||
} | ||
} | ||
|
||
void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) | ||
{ | ||
} | ||
|
||
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) | ||
{ | ||
foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) | ||
{ | ||
var dispatcher = cdb as ChannelDispatcher; | ||
foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints) | ||
{ | ||
if (!endpointDispatcher.IsSystemEndpoint) | ||
{ | ||
endpointDispatcher.DispatchRuntime.InstanceProvider = SystemWebHostDependencyInjectionInstanceProvider.Shared; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
165 changes: 0 additions & 165 deletions
165
...soft.Extensions.ServiceModel/DependencyInjection/SystemWebHostServiceBehaviorAttribute.cs
This file was deleted.
Oops, something went wrong.