-
-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to prove unload works ok with modules and onactivated in …
…the loop.
- Loading branch information
1 parent
7a3aaee
commit 430e28b
Showing
5 changed files
with
121 additions
and
1 deletion.
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
26 changes: 26 additions & 0 deletions
26
test/Autofac.Test.Scenarios.LoadContext/LifetimeScopeEndingModule.cs
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,26 @@ | ||
// Copyright (c) Autofac Project. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using Autofac; | ||
|
||
namespace A; | ||
|
||
public class LifetimeScopeEndingModule : Module | ||
{ | ||
private readonly Action _invokeOnEndCallback; | ||
|
||
public LifetimeScopeEndingModule(Action invokeOnEndCallback) | ||
{ | ||
_invokeOnEndCallback = invokeOnEndCallback; | ||
} | ||
|
||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterType<Service1>(); | ||
|
||
builder.RegisterBuildCallback(scope => scope.CurrentScopeEnding += (sender, ev) => | ||
{ | ||
_invokeOnEndCallback(); | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/Autofac.Test.Scenarios.LoadContext/OnActivatedModule.cs
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,21 @@ | ||
// Copyright (c) Autofac Project. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using Autofac; | ||
|
||
namespace A; | ||
|
||
public class OnActivatedModule : Module | ||
{ | ||
private readonly int _value; | ||
|
||
public OnActivatedModule(int value) | ||
{ | ||
_value = value; | ||
} | ||
|
||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterType<Service1>().OnActivated(x => x.Instance.Value = _value); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ namespace A; | |
|
||
public class Service1 | ||
{ | ||
public int Value { get; set; } | ||
} |