parent
6758010e1a
commit
9b061ececb
|
|
@ -32,6 +32,7 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_stop.Dispose();
|
_stop.Dispose();
|
||||||
|
(_services as IDisposable)?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,17 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Hosting.Fakes
|
namespace Microsoft.AspNet.Hosting.Fakes
|
||||||
{
|
{
|
||||||
public class FakeService : IFakeEveryService { }
|
public class FakeService : IFakeEveryService, IDisposable
|
||||||
|
{
|
||||||
|
public bool Disposed { get; private set; }
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Disposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
|
using Microsoft.AspNet.Hosting.Fakes;
|
||||||
using Microsoft.AspNet.Hosting.Internal;
|
using Microsoft.AspNet.Hosting.Internal;
|
||||||
using Microsoft.AspNet.Hosting.Server;
|
using Microsoft.AspNet.Hosting.Server;
|
||||||
using Microsoft.AspNet.Hosting.Startup;
|
using Microsoft.AspNet.Hosting.Startup;
|
||||||
|
|
@ -92,6 +93,32 @@ namespace Microsoft.AspNet.Hosting
|
||||||
Assert.Equal(1, _startInstances[0].DisposeCalls);
|
Assert.Equal(1, _startInstances[0].DisposeCalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HostingEngineDisposesServiceProvider()
|
||||||
|
{
|
||||||
|
var engine = CreateBuilder()
|
||||||
|
.UseServer(this)
|
||||||
|
.UseServices(s =>
|
||||||
|
{
|
||||||
|
s.AddTransient<IFakeService, FakeService>();
|
||||||
|
s.AddSingleton<IFakeSingletonService, FakeService>();
|
||||||
|
})
|
||||||
|
.UseStartup("Microsoft.AspNet.Hosting.Tests")
|
||||||
|
.Build()
|
||||||
|
.Start();
|
||||||
|
|
||||||
|
var singleton = (FakeService)engine.Services.GetService<IFakeSingletonService>();
|
||||||
|
var transient = (FakeService)engine.Services.GetService<IFakeService>();
|
||||||
|
|
||||||
|
Assert.False(singleton.Disposed);
|
||||||
|
Assert.False(transient.Disposed);
|
||||||
|
|
||||||
|
engine.Dispose();
|
||||||
|
|
||||||
|
Assert.True(singleton.Disposed);
|
||||||
|
Assert.True(transient.Disposed);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void HostingEngineNotifiesApplicationStarted()
|
public void HostingEngineNotifiesApplicationStarted()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue