Skip to content

Commit

Permalink
Merge pull request #45 from IharBury/TinyIoCKey
Browse files Browse the repository at this point in the history
TinyIoC container can resolve concrete types depending on a registered interface
  • Loading branch information
Erwinvandervalk authored Nov 16, 2016
2 parents dffa8b9 + f261bf9 commit 8ddd0d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 17 additions & 0 deletions Source/Core/Chill.Net45.Tests/TinyIocSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,33 @@ public void Then_resolving_concrete_type_twice_returns_the_same_object()
{
The<CodeObject>().Should().BeSameAs(The<CodeObject>());
}

[Fact]
public void Then_can_resolve_concrete_type_depending_on_a_registered_interface()
{
The<DependentService>().TestService.GetType().Should().Be(typeof(TestService));
}
}


public interface ITestService
{

}

public class TestService : ITestService
{

}

public class DependentService
{
public DependentService(ITestService testService)
{
TestService = testService;
}

public ITestService TestService { get; }
}
}
}
12 changes: 5 additions & 7 deletions Source/Core/Chill.Net45/TinyIocChillContainer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using TinyIoC;

namespace Chill
{
public class TinyIocChillContainer : IChillContainer
{
private TinyIoCContainer _container;
private readonly TinyIoCContainer _container;

public TinyIocChillContainer()
{
_container = new TinyIoCContainer();
Expand All @@ -32,12 +30,12 @@ public void RegisterType<T>() where T : class

public T Get<T>(string key = null) where T : class
{
return _container.Resolve<T>(key);
return _container.Resolve<T>(key ?? string.Empty);
}

public T Set<T>(T valueToSet, string key = null) where T : class
{
_container.Register<T>(valueToSet, key);
_container.Register(valueToSet, key ?? string.Empty);
return valueToSet;
}

Expand Down

0 comments on commit 8ddd0d5

Please sign in to comment.