Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created March 25, 2016 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadhi/7893f5cf9a37ec5c6fed to your computer and use it in GitHub Desktop.
Save dadhi/7893f5cf9a37ec5c6fed to your computer and use it in GitHub Desktop.
How in DryIoc InjectListOfDepsWithStringDeps
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