I have a decorator and actual implementation that looks like this:
public interface IAmUsedTwice
{
void DoSomething();
}
public class ForReal: IAmUsedTwice
{
public SomethingElse Need { get; set; }
public ForReal(SomethingElse iNeed)
{
Need = iNeed;
}
public void DoSomething()
{
Console.WriteLine("Realing doing something here");
}
}
public class SomethingElse {}
public class DecoratingIsFun: IAmUsedTwice
{
private IAmUsedTwice Actual { get; set; }
public DecoratingIsFun(IAmUsedTwice actual)
{
Actual = actual;
}
public void DoSomething()
{
Console.WriteLine("This is a decorator!");
Actual.DoSomething();
}
}
and the configuration was set up before I started this using xml for the actual implementation and looks something like this:
<component id="forReal"
service="SomeNamespace.IAmUsedTwice, SomeNamespace"
type="SomeNamespace.ForReal, SomeNamespace">
<parameters>
<iNeed>${iNeed}</iNeed>
</parameters>
</component>
and you can assume that the iNeed component is set up correctly already.
Now, the system is already configured to use the ForReal class, but what I want to do is swap out the ForReal class and use the DecoratingIsFun class now.
I created an installer to register the DecoratingIsFun class like so:
public class DecoratorInstaller: IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IAmUsedTwice>()
.ImplementedBy<DecoratingIsFun>()
);
}
}
However, I still need to tell it two things.
- When it resolves IAmUsedTwice I want it to resolve an instance of DecoratingIsFun from now on instead of the other class
- When resolving DecoratingIsFun I need it to resolve ForReal as a constructor argument for the instance it's creating.
The goal will be that I can then call windsorContainer.Resolve() and get a DecoratingIsFun instance.
How can I tell the installer to do that?