Skip to content

Commit 52f4717

Browse files
committed
resolved #161
1 parent 2a05307 commit 52f4717

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/CatLib.Core.Tests/Support/Container/ContainerTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,16 @@ public void TestGivenInvalidTypeNotSupportNullInject()
27832783
.Needs("$container").Given(() => null);
27842784
container.Make<TestGivenInvalidTypeClass>();
27852785
}
2786+
2787+
[TestMethod]
2788+
[ExpectedException(typeof(LogicException))]
2789+
public void TestSetAliasIsService()
2790+
{
2791+
var container = new Container();
2792+
container.Bind("abc", (c, p) => 1, false);
2793+
container.Bind("ccc", (c, p) => 1, false);
2794+
container.Alias("abc", "ccc");
2795+
}
27862796
#endregion
27872797

27882798
/// <summary>

src/CatLib.Core/Support/Container/Container.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ public IContainer Alias(string alias, string service)
350350
throw new LogicException($"Alias [{alias}] is already exists.");
351351
}
352352

353+
if (binds.ContainsKey(alias))
354+
{
355+
throw new LogicException($"Alias [{alias}] has been used for service name.");
356+
}
357+
353358
if (!binds.ContainsKey(service) && !instances.ContainsKey(service))
354359
{
355360
throw new CodeStandardException(

0 commit comments

Comments
 (0)