This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API changes to Hosting and TestServer #525
- Loading branch information
Showing
32 changed files
with
896 additions
and
657 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>485b6745-7648-400a-a969-f68fcf194e46</ProjectGuid> | ||
<RootNamespace>SampleStartups</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<DnxInvisibleContent Include="bower.json" /> | ||
<DnxInvisibleContent Include=".bowerrc" /> | ||
<DnxInvisibleContent Include="package.json" /> | ||
</ItemGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
// Note that this sample will not run. It is only here to illustrate usage patterns. | ||
|
||
namespace SampleStartups | ||
{ | ||
public class StartupBlockingOnStart | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Run(async (context) => | ||
{ | ||
await context.Response.WriteAsync("Hello World!"); | ||
}); | ||
} | ||
|
||
// Entry point for the application. | ||
public static void Main(string[] args) | ||
{ | ||
var config = WebApplicationConfiguration.GetDefault(args); | ||
|
||
var application = new WebApplicationBuilder() | ||
.UseConfiguration(config) | ||
.UseStartup<StartupBlockingOnStart>() | ||
.Build(); | ||
|
||
using (application.Start()) | ||
{ | ||
Console.ReadLine(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
// Note that this sample will not run. It is only here to illustrate usage patterns. | ||
|
||
namespace SampleStartups | ||
{ | ||
public class StartupConfigureAddresses | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Run(async (context) => | ||
{ | ||
await context.Response.WriteAsync("Hello World!"); | ||
}); | ||
} | ||
|
||
// Entry point for the application. | ||
public static void Main(string[] args) | ||
{ | ||
var config = WebApplicationConfiguration.GetDefault(args); | ||
|
||
var application = new WebApplicationBuilder() | ||
.UseConfiguration(config) | ||
.UseStartup<StartupConfigureAddresses>() | ||
.Build(); | ||
|
||
var addresses = application.GetAddresses(); | ||
addresses.Add("http://localhost:5000"); | ||
addresses.Add("http://localhost:5001"); | ||
|
||
application.Run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
// Note that this sample will not run. It is only here to illustrate usage patterns. | ||
|
||
namespace SampleStartups | ||
{ | ||
public class StartupExternallyControlled | ||
{ | ||
private readonly IWebApplication _host; | ||
private IDisposable _application; | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Run(async (context) => | ||
{ | ||
await context.Response.WriteAsync("Hello World!"); | ||
}); | ||
} | ||
|
||
public StartupExternallyControlled() | ||
{ | ||
_host = new WebApplicationBuilder().UseStartup<StartupExternallyControlled>().Build(); | ||
|
||
// Clear all configured addresses | ||
_host.GetAddresses().Clear(); | ||
} | ||
|
||
public void Start() | ||
{ | ||
_application = _host.Start(); | ||
} | ||
|
||
public void Stop() | ||
{ | ||
_application.Dispose(); | ||
} | ||
|
||
public void AddUrl(string url) | ||
{ | ||
var addresses = _host.GetAddresses(); | ||
|
||
addresses.Add(url); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
// Note that this sample will not run. It is only here to illustrate usage patterns. | ||
|
||
namespace SampleStartups | ||
{ | ||
public class StartupFullControl | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var application = new WebApplicationBuilder() | ||
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") // Set the server manually | ||
.UseEnvironment("Development") | ||
.UseWebRoot("public") | ||
.ConfigureLogging(loggerFactory => | ||
{ | ||
loggerFactory.AddProvider(new MyHostLoggerProvider()); | ||
}) | ||
.ConfigureServices(services => | ||
{ | ||
// Configure services that the application can see | ||
services.AddSingleton<IMyCustomService, MyCustomService>(); | ||
}) | ||
.Configure(app => | ||
{ | ||
// Write the application inline, this won't call any startup class in the assembly | ||
app.Use(next => context => | ||
{ | ||
return next(context); | ||
}); | ||
}) | ||
.Build(); | ||
|
||
application.Run(); | ||
} | ||
} | ||
|
||
public class MyHostLoggerProvider : ILoggerProvider | ||
{ | ||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public interface IMyCustomService | ||
{ | ||
void Go(); | ||
} | ||
|
||
public class MyCustomService : IMyCustomService | ||
{ | ||
public void Go() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
// Note that this sample will not run. It is only here to illustrate usage patterns. | ||
|
||
namespace SampleStartups | ||
{ | ||
public class StartupHelloWorld | ||
{ | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.Run(async (context) => | ||
{ | ||
await context.Response.WriteAsync("Hello World!"); | ||
}); | ||
} | ||
|
||
// Entry point for the application. | ||
public static void Main(string[] args) | ||
{ | ||
var config = WebApplicationConfiguration.GetDefault(args); | ||
|
||
var application = new WebApplicationBuilder() | ||
.UseConfiguration(config) | ||
.UseStartup<StartupHelloWorld>() | ||
.Build(); | ||
|
||
application.Run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"dependencies": { | ||
"Microsoft.AspNet.Hosting": "1.0.0-*" | ||
}, | ||
"frameworks": { | ||
"dnx451": { }, | ||
"dnxcore50": { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNet.Http.Features; | ||
|
||
namespace Microsoft.AspNet.Hosting | ||
{ | ||
/// <summary> | ||
/// Represents a configured web application | ||
/// </summary> | ||
public interface IWebApplication | ||
{ | ||
/// <summary> | ||
/// The <see cref="IFeatureCollection"/> exposed by the configured server. | ||
/// </summary> | ||
IFeatureCollection ServerFeatures { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="IServiceProvider"/> for the application. | ||
/// </summary> | ||
IServiceProvider Services { get; } | ||
|
||
/// <summary> | ||
/// Starts listening on the configured addresses. | ||
/// </summary> | ||
/// <returns></returns> | ||
IDisposable Start(); | ||
} | ||
} |
Oops, something went wrong.