Fixed stack overflow when setting RequestServices
- Added tests
This commit is contained in:
parent
cde733a63a
commit
520fc2b5fd
|
|
@ -55,8 +55,8 @@ namespace Microsoft.AspNet.Hosting.Internal
|
|||
|
||||
set
|
||||
{
|
||||
_requestServices = value;
|
||||
_requestServicesSet = true;
|
||||
RequestServices = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,6 +151,31 @@ namespace Microsoft.AspNet.TestHost
|
|||
Assert.Equal("Success", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanSetCustomServiceProvider()
|
||||
{
|
||||
var server = TestServer.Create(app =>
|
||||
{
|
||||
app.Run(context =>
|
||||
{
|
||||
context.ApplicationServices = new ServiceCollection()
|
||||
.AddTransient<TestService>()
|
||||
.BuildServiceProvider();
|
||||
|
||||
context.RequestServices = new ServiceCollection()
|
||||
.AddTransient<TestService>()
|
||||
.BuildServiceProvider();
|
||||
|
||||
var s1 = context.ApplicationServices.GetRequiredService<TestService>();
|
||||
var s2 = context.RequestServices.GetRequiredService<TestService>();
|
||||
|
||||
return context.Response.WriteAsync("Success");
|
||||
});
|
||||
});
|
||||
string result = await server.CreateClient().GetStringAsync("/path");
|
||||
Assert.Equal("Success", result);
|
||||
}
|
||||
|
||||
public class ReplaceServiceProvidersFeatureFilter : IStartupFilter, IServiceProvidersFeature
|
||||
{
|
||||
public ReplaceServiceProvidersFeatureFilter(IServiceProvider appServices, IServiceProvider requestServices)
|
||||
|
|
@ -232,6 +257,7 @@ namespace Microsoft.AspNet.TestHost
|
|||
Assert.Equal("Success", result);
|
||||
}
|
||||
|
||||
|
||||
public class EnsureApplicationServicesFilter : IStartupFilter
|
||||
{
|
||||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
|
||||
|
|
|
|||
Loading…
Reference in New Issue