Skip to content

Commit

Permalink
Merge pull request #17 from paulomorgado/features/servicemodel
Browse files Browse the repository at this point in the history
Improvements on service behavior
  • Loading branch information
paulomorgado authored Jul 16, 2021
2 parents f831816 + 7544410 commit d8944d0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 167 deletions.
3 changes: 2 additions & 1 deletion demo/SampleWebApplication/ServiceModel/Feed.svc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

namespace SampleWebApplication.ServiceModel
{
[SystemWebHostServiceBehavior()]
[ServiceBehavior()]
[SystemWebHostDependencyInjection()]
public class Feed : IFeed
{
private readonly ISyndicationClient syndicationClient;
Expand Down
5 changes: 4 additions & 1 deletion demo/SampleWebApplication/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"
minFreeMemoryPercentageToActivateService="0" />
</system.serviceModel>
</configuration>
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;
}
}
}
}

}
}

This file was deleted.

0 comments on commit d8944d0

Please sign in to comment.