Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit ddc7f08

Browse files
committed
#116 - Add IBuilder.Properties collection.
1 parent 7230a3d commit ddc7f08

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

src/Microsoft.AspNet.Http/IBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56

67
namespace Microsoft.AspNet.Builder
78
{
89
public interface IBuilder
910
{
1011
IServiceProvider ApplicationServices { get; set; }
12+
1113
IServerInformation Server { get; set; }
1214

15+
IDictionary<string, object> Properties { get; set; }
16+
1317
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
1418

1519
IBuilder New();
20+
1621
RequestDelegate Build();
1722
}
1823
}

src/Microsoft.AspNet.PipelineCore/Builder.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Threading.Tasks;
88
using Microsoft.AspNet.Http;
9+
using Microsoft.AspNet.Http.Infrastructure;
910

1011
namespace Microsoft.AspNet.Builder
1112
{
@@ -15,17 +16,51 @@ public class Builder : IBuilder
1516

1617
public Builder(IServiceProvider serviceProvider)
1718
{
19+
Properties = new Dictionary<string, object>();
1820
ApplicationServices = serviceProvider;
1921
}
2022

2123
private Builder(Builder builder)
2224
{
23-
ApplicationServices = builder.ApplicationServices;
24-
Server = builder.Server;
25+
Properties = builder.Properties;
2526
}
2627

27-
public IServiceProvider ApplicationServices { get; set; }
28-
public IServerInformation Server { get; set; }
28+
public IServiceProvider ApplicationServices
29+
{
30+
get
31+
{
32+
return GetProperty<IServiceProvider>(Constants.BuilderProperties.ApplicationServices);
33+
}
34+
set
35+
{
36+
SetProperty<IServiceProvider>(Constants.BuilderProperties.ApplicationServices, value);
37+
}
38+
}
39+
40+
public IServerInformation Server
41+
{
42+
get
43+
{
44+
return GetProperty<IServerInformation>(Constants.BuilderProperties.ServerInformation);
45+
}
46+
set
47+
{
48+
SetProperty<IServerInformation>(Constants.BuilderProperties.ServerInformation, value);
49+
}
50+
}
51+
52+
public IDictionary<string, object> Properties { get; set; }
53+
54+
private T GetProperty<T>(string key)
55+
{
56+
object value;
57+
return Properties.TryGetValue(key, out value) ? (T)value : default(T);
58+
}
59+
60+
private void SetProperty<T>(string key, T value)
61+
{
62+
Properties[key] = value;
63+
}
2964

3065
public IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
3166
{

src/Microsoft.AspNet.PipelineCore/Infrastructure/Constants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@ internal static class Headers
2525
internal const string Expires = "Expires";
2626
internal const string WebSocketSubProtocols = "Sec-WebSocket-Protocol";
2727
}
28+
29+
internal static class BuilderProperties
30+
{
31+
internal static string ServerInformation = "server.Information";
32+
internal static string ApplicationServices = "application.Services";
33+
}
2834
}
2935
}

0 commit comments

Comments
 (0)