#116 - Add IBuilder.Properties collection.
This commit is contained in:
parent
7230a3d78e
commit
ddc7f08957
|
|
@ -2,17 +2,22 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Builder
|
namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
public interface IBuilder
|
public interface IBuilder
|
||||||
{
|
{
|
||||||
IServiceProvider ApplicationServices { get; set; }
|
IServiceProvider ApplicationServices { get; set; }
|
||||||
|
|
||||||
IServerInformation Server { get; set; }
|
IServerInformation Server { get; set; }
|
||||||
|
|
||||||
|
IDictionary<string, object> Properties { get; set; }
|
||||||
|
|
||||||
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
|
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
|
||||||
|
|
||||||
IBuilder New();
|
IBuilder New();
|
||||||
|
|
||||||
RequestDelegate Build();
|
RequestDelegate Build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.AspNet.Http.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Builder
|
namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
|
|
@ -15,17 +16,51 @@ namespace Microsoft.AspNet.Builder
|
||||||
|
|
||||||
public Builder(IServiceProvider serviceProvider)
|
public Builder(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
|
Properties = new Dictionary<string, object>();
|
||||||
ApplicationServices = serviceProvider;
|
ApplicationServices = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Builder(Builder builder)
|
private Builder(Builder builder)
|
||||||
{
|
{
|
||||||
ApplicationServices = builder.ApplicationServices;
|
Properties = builder.Properties;
|
||||||
Server = builder.Server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IServiceProvider ApplicationServices { get; set; }
|
public IServiceProvider ApplicationServices
|
||||||
public IServerInformation Server { get; set; }
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetProperty<IServiceProvider>(Constants.BuilderProperties.ApplicationServices);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty<IServiceProvider>(Constants.BuilderProperties.ApplicationServices, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IServerInformation Server
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetProperty<IServerInformation>(Constants.BuilderProperties.ServerInformation);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty<IServerInformation>(Constants.BuilderProperties.ServerInformation, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDictionary<string, object> Properties { get; set; }
|
||||||
|
|
||||||
|
private T GetProperty<T>(string key)
|
||||||
|
{
|
||||||
|
object value;
|
||||||
|
return Properties.TryGetValue(key, out value) ? (T)value : default(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetProperty<T>(string key, T value)
|
||||||
|
{
|
||||||
|
Properties[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
public IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
|
public IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,11 @@ namespace Microsoft.AspNet.Http.Infrastructure
|
||||||
internal const string Expires = "Expires";
|
internal const string Expires = "Expires";
|
||||||
internal const string WebSocketSubProtocols = "Sec-WebSocket-Protocol";
|
internal const string WebSocketSubProtocols = "Sec-WebSocket-Protocol";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static class BuilderProperties
|
||||||
|
{
|
||||||
|
internal static string ServerInformation = "server.Information";
|
||||||
|
internal static string ApplicationServices = "application.Services";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue