-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lamar supports keyed services through the .NET spec
- Loading branch information
1 parent
0c35818
commit cab25a0
Showing
5 changed files
with
111 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
49 changes: 49 additions & 0 deletions
49
src/Lamar.Testing/IoC/Acceptance/IKeyedServiceProvider_compliance.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,49 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Shouldly; | ||
using StructureMap.Testing.Widget; | ||
using Xunit; | ||
|
||
namespace Lamar.Testing.IoC.Acceptance; | ||
|
||
#if NET8_0_OR_GREATER | ||
public class IKeyedServiceProvider_compliance | ||
{ | ||
#region sample_adding_keyed_services | ||
|
||
[Fact] | ||
public void register_by_name_using_dot_net_core_syntax() | ||
{ | ||
var container = Container.For(services => | ||
{ | ||
services.AddKeyedSingleton<IWidget, AWidget>("one"); | ||
services.AddKeyedScoped<IWidget>("two", (_, _) => new BWidget()); | ||
services.AddKeyedSingleton<IWidget>("three", new CWidget()); | ||
services.AddKeyedSingleton<CWidget>("C1"); | ||
services.AddKeyedSingleton<CWidget>("C2"); | ||
services.AddKeyedSingleton<CWidget>("C3"); | ||
}); | ||
|
||
container.GetInstance<IWidget>("one").ShouldBeOfType<AWidget>(); | ||
container.GetKeyedService<IWidget>("one").ShouldBeOfType<AWidget>(); | ||
|
||
container.GetInstance<IWidget>("two").ShouldBeOfType<BWidget>(); | ||
container.GetKeyedService<IWidget>("two").ShouldBeOfType<BWidget>(); | ||
|
||
container.GetInstance<IWidget>("three").ShouldBeOfType<CWidget>(); | ||
container.GetKeyedService<IWidget>("three").ShouldBeOfType<CWidget>(); | ||
|
||
container.GetInstance<CWidget>("C1").ShouldBeOfType<CWidget>(); | ||
container.GetKeyedService<CWidget>("C2").ShouldBeOfType<CWidget>(); | ||
|
||
container.GetKeyedService<CWidget>("C2") | ||
.ShouldBeSameAs(container.GetKeyedService<CWidget>("C2")); | ||
|
||
container.GetKeyedService<CWidget>("C2") | ||
.ShouldNotBeSameAs(container.GetKeyedService<CWidget>("C3")); | ||
} | ||
|
||
#endregion | ||
} | ||
#endif |
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
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