#116 - Add IBuilder.Properties collection.

This commit is contained in:
Chris Ross 2014-08-20 12:38:04 -07:00
parent 7230a3d78e
commit ddc7f08957
3 changed files with 50 additions and 4 deletions

View File

@ -2,17 +2,22 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Microsoft.AspNet.Builder
{
public interface IBuilder
{
IServiceProvider ApplicationServices { get; set; }
IServerInformation Server { get; set; }
IDictionary<string, object> Properties { get; set; }
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
IBuilder New();
RequestDelegate Build();
}
}

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Infrastructure;
namespace Microsoft.AspNet.Builder
{
@ -15,17 +16,51 @@ namespace Microsoft.AspNet.Builder
public Builder(IServiceProvider serviceProvider)
{
Properties = new Dictionary<string, object>();
ApplicationServices = serviceProvider;
}
private Builder(Builder builder)
{
ApplicationServices = builder.ApplicationServices;
Server = builder.Server;
Properties = builder.Properties;
}
public IServiceProvider ApplicationServices { get; set; }
public IServerInformation Server { get; set; }
public IServiceProvider ApplicationServices
{
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)
{

View File

@ -25,5 +25,11 @@ namespace Microsoft.AspNet.Http.Infrastructure
internal const string Expires = "Expires";
internal const string WebSocketSubProtocols = "Sec-WebSocket-Protocol";
}
internal static class BuilderProperties
{
internal static string ServerInformation = "server.Information";
internal static string ApplicationServices = "application.Services";
}
}
}