Search code examples
dependency-injectioninversion-of-controlcastle-windsorcastle

How to update already registered service Castle Windsor


I'm a beginner to the DI containers.

I'm using third party framework and it has a class like below

public class PurchaseOrderAppService : IPurchaseOrderAppService, IAutoRegister
    {
        private readonly IEmail _email;

        public PurchaseOrderAppService(IEmail email)
        {
            _email = email;
        }
    }

All classes that inherits IAutoRegister interface are automatically registered by the third party framework. Email class is like below

public class Email : IEmail, IAutoRegister
{
    public Send(string message)
    {
        //Send a message
    }
}

What I want is that I want PurchaseOrderAppService class to use another class called MyEmail instead of Email.

public class MyEmail : IEmail
{
    public Send(string message)
    {
        //Send a message another way
    }
}

How can I update already registered service by framework?

Thanks.


Solution

  • Updating registered service is not a right way to do with IoC container and is not something you need. I would suggest you have a look at https://github.com/castleproject/Windsor/blob/master/docs/inline-dependencies.md and https://github.com/castleproject/Windsor/blob/master/docs/registering-components-one-by-one.md#supplying-the-component-for-a-dependency-to-use-service-override