Skip to content

Commit 29dbccb

Browse files
committedApr 26, 2018
Adds overloads to endpoint builder
1 parent 93708f2 commit 29dbccb

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed
 

‎Solid.AspNetCore.Extensions.Wcf.Tests/Host/MulitpleContractTestStartup.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public void Configure(IApplicationBuilder builder)
2525
.Use(async (context, next) =>
2626
{
2727
if(context.Request.Path.StartsWithSegments("/replaceecho"))
28-
context.Request.Path = "/multiple/echo";
28+
context.Request.Path = "/multiple/endpoints/echo/endpoint";
2929
await next();
3030
})
31-
.UseWcfService<MultipleContract>("/multiple", b => b.AddServiceEndpoint<IEchoContract>("/echo").AddServiceEndpoint<ICounterContract>("counter"));
31+
.UseWcfService<MultipleContract>("/multiple/endpoints", b =>
32+
b.AddServiceEndpoint<IEchoContract>("/echo/endpoint").AddServiceEndpoint<ICounterContract>("counter/endpoint"));
3233
}
3334

3435
ServiceHost CreateServiceHost(IServiceProvider provider, MultipleContract singleton, Type type, Uri[] baseAddresses)

‎Solid.AspNetCore.Extensions.Wcf.Tests/MultipleContractTestFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public IEchoContract GetEchoService()
2929
{
3030
if (_echo == null)
3131
{
32-
var url = new Uri(TestingServer.BaseAddress, "multiple/echo");
32+
var url = new Uri(TestingServer.BaseAddress, "multiple/endpoints/echo/endpoint");
3333
var binding = new BasicHttpBinding();
3434
var endpoint = new EndpointAddress(url);
3535
var factory = new ChannelFactory<IEchoContract>(binding, endpoint);
@@ -69,7 +69,7 @@ public ICounterContract GetCounterService()
6969
{
7070
if (_counter == null)
7171
{
72-
var url = new Uri(TestingServer.BaseAddress, "multiple/counter");
72+
var url = new Uri(TestingServer.BaseAddress, "multiple/endpoints/counter/endpoint");
7373
var binding = new BasicHttpBinding();
7474
var endpoint = new EndpointAddress(url);
7575
var factory = new ChannelFactory<ICounterContract>(binding, endpoint);

‎Solid.AspNetCore.Extensions.Wcf/Abstractions/IEndpointBuilder.cs

+39-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.ServiceModel.Channels;
6+
using System.ServiceModel.Description;
67
using System.Text;
78
using System.Threading.Tasks;
89

@@ -21,6 +22,14 @@ public interface IEndpointBuilder<TService>
2122
/// <returns>The endpoint builder</returns>
2223
IEndpointBuilder<TService> AddServiceEndpoint<TContract>();
2324

25+
/// <summary>
26+
/// Adds a service endpoint using the default binding to the base address of a service host
27+
/// </summary>
28+
/// <typeparam name="TContract">The contract type of the service endpoint</typeparam>
29+
/// <param name="action">An action to alter the ServiceEndpoint</param>
30+
/// <returns>The endpoint builder</returns>
31+
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Action<IServiceProvider, ServiceEndpoint> action);
32+
2433
/// <summary>
2534
/// Adds a service endpoint using the default binding to a specified path on a service host
2635
/// </summary>
@@ -29,22 +38,50 @@ public interface IEndpointBuilder<TService>
2938
/// <returns>The endpoint builder</returns>
3039
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(string path);
3140

41+
/// <summary>
42+
/// Adds a service endpoint using the default binding to a specified path on a service host
43+
/// </summary>
44+
/// <typeparam name="TContract">The contract type of the service endpoint</typeparam>
45+
/// <param name="path">The sub path for the endpoint</param>
46+
/// <param name="action">An action to alter the ServiceEndpoint</param>
47+
/// <returns>The endpoint builder</returns>
48+
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(string path, Action<IServiceProvider, ServiceEndpoint> action);
49+
3250
/// <summary>
3351
/// Adds a service endpoint using the provided binding to the base address of a service host
3452
/// </summary>
3553
/// <typeparam name="TContract">The contract type of the service endpoint</typeparam>
36-
/// <param name="binding"></param>
54+
/// <param name="binding">The binding for the endpoint</param>
3755
/// <returns>The endpoint builder</returns>
3856
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding);
3957

58+
/// <summary>
59+
/// Adds a service endpoint using the provided binding to the base address of a service host
60+
/// </summary>
61+
/// <typeparam name="TContract">The contract type of the service endpoint</typeparam>
62+
/// <param name="binding">The binding for the endpoint</param>
63+
/// <param name="action">An action to alter the ServiceEndpoint</param>
64+
/// <returns>The endpoint builder</returns>
65+
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding, Action<IServiceProvider, ServiceEndpoint> action);
66+
4067
/// <summary>
4168
/// Adds a service endpoint using the provided binding to a specified path on a service host
4269
/// </summary>
4370
/// <typeparam name="TContract">The contract type of the service endpoint</typeparam>
44-
/// <param name="binding"></param>
71+
/// <param name="binding">The binding for the endpoint</param>
4572
/// <param name="path">The sub path for the endpoint</param>
4673
/// <returns>The endpoint builder</returns>
4774
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding, string path);
4875

76+
/// <summary>
77+
/// Adds a service endpoint using the provided binding to a specified path on a service host
78+
/// </summary>
79+
/// <typeparam name="TContract">The contract type of the service endpoint</typeparam>
80+
/// <param name="binding">The binding for the endpoint</param>
81+
/// <param name="path">The sub path for the endpoint</param>
82+
/// <param name="action">An action to alter the ServiceEndpoint</param>
83+
/// <returns>The endpoint builder</returns>
84+
IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding, string path, Action<IServiceProvider, ServiceEndpoint> action);
85+
4986
}
5087
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Solid.AspNetCore.Extensions.Wcf.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.ServiceModel;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Solid.AspNetCore.Extensions.Wcf.Abstractions
10+
{
11+
internal interface IServiceHostFactoryDelegateFactory
12+
{
13+
ServiceHostFactoryDelegate<TService> Create<TService, TServiceHost>()
14+
where TServiceHost : ServiceHost;
15+
}
16+
}

‎Solid.AspNetCore.Extensions.Wcf/Builders/EndpointBuilder.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using Microsoft.Extensions.DependencyInjection;
1111
using System.ServiceModel;
12+
using System.ServiceModel.Description;
1213

1314
namespace Solid.AspNetCore.Extensions.Wcf.Builders
1415
{
@@ -41,7 +42,30 @@ public IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding)
4142

4243
public IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding, string path)
4344
{
44-
_host.AddServiceEndpoint(typeof(TContract), SanitizeBinding(binding), path);
45+
return AddServiceEndpoint<TContract>(binding, path, (_1, _2) => { });
46+
}
47+
48+
public IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Action<IServiceProvider, ServiceEndpoint> action)
49+
{
50+
var binding = _services.GetService<Binding>();
51+
return AddServiceEndpoint<TContract>(binding, action);
52+
}
53+
54+
public IEndpointBuilder<TService> AddServiceEndpoint<TContract>(string path, Action<IServiceProvider, ServiceEndpoint> action)
55+
{
56+
var binding = _services.GetService<Binding>();
57+
return AddServiceEndpoint<TContract>(binding, path, action);
58+
}
59+
60+
public IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding, Action<IServiceProvider, ServiceEndpoint> action)
61+
{
62+
return AddServiceEndpoint<TContract>(binding, string.Empty, action);
63+
}
64+
65+
public IEndpointBuilder<TService> AddServiceEndpoint<TContract>(Binding binding, string path, Action<IServiceProvider, ServiceEndpoint> action)
66+
{
67+
var endpoint = _host.AddServiceEndpoint(typeof(TContract), SanitizeBinding(binding), path);
68+
action(_services, endpoint);
4569
return this;
4670
}
4771

0 commit comments

Comments
 (0)
Please sign in to comment.