-
-
Save WooCode/81eaa994852679f90bdb to your computer and use it in GitHub Desktop.
Example for DiDay (from the tests)
This file contains 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
[TestClass] | |
public class DiDayTests | |
{ | |
[TestMethod] | |
public void ResolveType() | |
{ | |
var di = new DiDay(); // or DiDay.Default; | |
di.Register<IBar>(d => new Bar(d.Resolve<IFoo>())); // Register Factory | |
di.Register<IFoo>(new Foo("Kristoffer")); // Register Instance | |
var bar = di.Resolve<IBar>(); | |
Assert.IsNotNull(bar); | |
Assert.AreEqual(bar.FooInstance.Name, "Kristoffer"); | |
} | |
[TestMethod] | |
public void ManualResolveType() | |
{ | |
var di = new DiDay(); // or DiDay.Default; | |
di.ManualResolver = type => | |
{ | |
return type == typeof (IFoo) ? new Foo("Test") : null; | |
}; | |
di.Register<IBar>(d => new Bar(d.Resolve<IFoo>())); // Register Factory | |
var bar = di.Resolve<IBar>(); | |
Assert.IsNotNull(bar); | |
Assert.AreEqual(bar.FooInstance.Name, "Test"); | |
} | |
[TestMethod] | |
[ExpectedExceptionAttribute(typeof(ResolveFailedException))] | |
public void ManualResolveFail() | |
{ | |
var di = new DiDay(); // or DiDay.Default; | |
di.Register<IBar>(d => new Bar(d.Resolve<IFoo>())); // Register Factory | |
var bar = di.Resolve<IBar>(); | |
Assert.IsNotNull(bar); | |
Assert.AreEqual(bar.FooInstance.Name, "Test"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment