Created
March 25, 2016 11:58
-
-
Save dadhi/7893f5cf9a37ec5c6fed to your computer and use it in GitHub Desktop.
How in DryIoc InjectListOfDepsWithStringDeps
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using NUnit.Framework; | |
namespace DryIoc.IssuesTests | |
{ | |
[TestFixture] | |
public class InjectListOfDepsWithStringDeps | |
{ | |
[Test] | |
public void Test() | |
{ | |
var container = new Container(); | |
container.Register<B>(); | |
container.RegisterInstance("a", serviceKey: "x"); | |
container.RegisterInstance("b", serviceKey: "y"); | |
container.Register(Made.Of(() => GetBs(Arg.Of<Func<string, B>>(), Arg.Of<KeyValuePair<string, string>[]>()))); | |
container.Register<A>(Reuse.Singleton); | |
var a = container.Resolve<A>(); | |
Assert.AreEqual(2, a.Bs.Count); | |
} | |
public static IList<B> GetBs(Func<string, B> getB, KeyValuePair<string, string>[] ss) | |
{ | |
return ss.Select(s => getB(s.Value)).ToList(); | |
} | |
public class B | |
{ | |
public string Message { get; private set; } | |
public B(string message) | |
{ | |
Message = message; | |
} | |
} | |
public class A | |
{ | |
public IList<B> Bs { get; private set; } | |
public A(IList<B> bs) | |
{ | |
Bs = bs; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment