Created
December 11, 2009 15:05
-
-
Save kkozmic/254244 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
[Test] | |
public void Can_dynamically_override_service_overrides() | |
{ | |
kernel.Register( | |
Component.For<ICustomer>() | |
.ImplementedBy<CustomerImpl>() | |
.Named("defaultCustomer"), | |
Component.For<ICustomer>().ImplementedBy<CustomerImpl2>() | |
.Named("otherCustomer") | |
.Parameters( | |
Parameter.ForKey("name").Eq("foo"), // static parameters, resolved at registration time | |
Parameter.ForKey("address").Eq("bar st 13"), | |
Parameter.ForKey("age").Eq("5")), | |
Component.For<CommonImplWithDependancy>() | |
.LifeStyle.Transient | |
.ServiceOverrides( | |
ServiceOverride.ForKey("customer").Eq("otherCustomer")) | |
.DynamicParameters((k, d) => // dynamic parameters | |
{ | |
var randomNumber = 2; | |
if (randomNumber == 2) | |
{ | |
d["customer"] = k.Resolve<ICustomer>("defaultCustomer"); | |
} | |
})); | |
var component = kernel.Resolve<CommonImplWithDependancy>(); | |
Assert.IsInstanceOf<CustomerImpl>(component.Customer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment