AppDomain safety
This commit is contained in:
parent
855974f128
commit
0a5f8e013e
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
#if NET451
|
||||
using System;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
#else
|
||||
|
|
@ -13,7 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
public class ActionContextAccessor : IActionContextAccessor
|
||||
{
|
||||
#if NET451
|
||||
private static string Key = typeof(ActionContext).FullName;
|
||||
private static readonly string Key = typeof(ActionContext).FullName + AppDomain.CurrentDomain.Id;
|
||||
|
||||
public ActionContext ActionContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
// 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 Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||
{
|
||||
#if NET451
|
||||
public class ActionContextAccessorTests
|
||||
{
|
||||
private static void DomainFunc()
|
||||
{
|
||||
var accessor = new ActionContextAccessor();
|
||||
Assert.Equal(null, accessor.ActionContext);
|
||||
accessor.ActionContext = new ActionContext();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChangingAppDomainsDoesNotBreak_ActionContextAccessor()
|
||||
{
|
||||
// Arrange
|
||||
var accessor = new ActionContextAccessor();
|
||||
var context = new ActionContext();
|
||||
var domain = AppDomain.CreateDomain("newDomain");
|
||||
|
||||
// Act
|
||||
domain.DoCallBack(DomainFunc);
|
||||
AppDomain.Unload(domain);
|
||||
accessor.ActionContext = context;
|
||||
|
||||
// Assert
|
||||
Assert.True(ReferenceEquals(context, accessor.ActionContext));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Loading…
Reference in New Issue