What I have is a stage, some interfaces, and also registration section. The problem is I need to defined some parameters as fixed and others as variables.
interface IDoSomething {
void DoWork();
}
interface IDoMath(){
void DoWork();
}
interface IBehaviorBusiness{
void Do();
}
class BehaviorBusiness {
...
public BehaviorBusiness(IDoSomething doSomething, IDoMatch doMatch, string connection){};
...
}
Is it possible with windsor container to define a parameter connection in declaration, and take IDosomething
and IDoMatch
from the container?
container.Register(
Component.For<IDoSomething>()
...
}
container.Register(
Component.For<IDoMatch>()
...
);
That is the concrete problem.
container.Register(
Component.For<IBehaviorBusiness>()
.ImplementedBy<BehaviorBusiness>()
.DependsOn(Dependency.OnComponent<IDoSomething, [default]>(),
Dependency.OnComponent<IDoMatch, [default]>(),
Dependency.OnValue("connection", connectionString))
.LifeStyle.Transient
);
Which is correct syntax if it exists?
If the connection string comes from your application settings, then use Dependency.OnAppSettingsValue()
:
container.Register(
Component.For<IBehaviorBusiness>()
.ImplementedBy<BehaviorBusiness>()
.DependsOn(Dependency.OnAppSettingsValue("connection", "connectionString"))
.LifeStyle.Transient
);
Here, "connection" is the name of the parameter in the class' constructor, and "connectionString" is the key of your connection string value in your application settings (i.e. Web.Config). You don't need to specify the other values, Windsor will resolve them as it usually does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With