Created
May 12, 2016 13:17
-
-
Save Pondidum/e3bb80340382ed83ce767cd18efc19fd to your computer and use it in GitHub Desktop.
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
| public class Scratchpad | |
| { | |
| [Fact] | |
| public void When_testing_something() | |
| { | |
| var container = new Container(c => | |
| { | |
| c.Scan(a => | |
| { | |
| a.TheCallingAssembly(); | |
| a.WithDefaultConventions(); | |
| a.AddAllTypesOf<ISource>(); | |
| }); | |
| c.For<ISource>().Use(context => context.GetInstance<SourceFactory>().GetSource("first")); | |
| }); | |
| container.GetInstance<ISource>().ShouldBeOfType<FirstSource>(); | |
| } | |
| } | |
| public class SourceFactory | |
| { | |
| private readonly List<ISource> _sources; | |
| public SourceFactory(IEnumerable<ISource> sources) | |
| { | |
| _sources = sources.ToList(); | |
| } | |
| public ISource GetSource(string name) | |
| { | |
| return _sources.Single(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); | |
| } | |
| } | |
| public interface ISource | |
| { | |
| string Name { get; } | |
| } | |
| public class FirstSource : ISource | |
| { | |
| public string Name { get { return "First Source"; } } | |
| } | |
| public class Second : ISource | |
| { | |
| public string Name { get { return "Second Source"; } } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment