Skip to content

Commit

Permalink
Merge pull request #57 from CatLib/1.0
Browse files Browse the repository at this point in the history
container add guard
  • Loading branch information
喵喵大人 authored Sep 8, 2017
2 parents 44233a7 + 33837ca commit 78c3d09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions projects/CatLib.API/Support/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public IContainer Alias(string alias, string service)
Guard.NotEmptyOrNull(alias, "alias");
Guard.NotEmptyOrNull(service, "service");

if (alias == service)
{
throw new RuntimeException("Alias is Same as Service Name: [" + alias + "].");
}

alias = Normalize(alias);
service = Normalize(service);

Expand Down
11 changes: 11 additions & 0 deletions projects/CatLib.Tests/Support/Container/ContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,17 @@ public void TestReleaseAllStaticService()
Assert.AreEqual(null, container.Make("Test"));
}

[TestMethod]
public void TestSameAliaseServiceName()
{
var container = MakeContainer();

ExceptionAssert.Throws<RuntimeException>(() =>
{
container.Singleton<ContainerTest>().Alias<ContainerTest>();
});
}

public class TestParamsMakeClass
{
public TestParamsMakeClass()
Expand Down

0 comments on commit 78c3d09

Please sign in to comment.