Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:50:47+00:00 2026-05-16T10:50:47+00:00

I want to redefine an (default) implementation in a given windsor-container. Is that what

  • 0

I want to redefine an (default) implementation in a given windsor-container. Is that what OverWrite is for? Doesn’t work, though.

container.Register(
                    Component.For<IServiceOperationAuthorization>()
                            .OverWrite()
                            .Instance(_authorization)
                    );

Any other Ideas?

cheers,
Lars

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:50:48+00:00Added an answer on May 16, 2026 at 10:50 am

    I actually found a nice solution where I combine xml-files for overrides and use fluent registrations for defaults.

    The fluent-API takes the fullname of a impl as the default key. On the fly I override the id’s of the xml-config to imitate the key-conventions of the fluent-API.

    Then i register the xml-config while I listen to Kernel.ComponentRegistered.

    Afterwards I only add services from the code-config where the xml hasn’t yet defined the service.

    (it’s a while ago and I just copy-pasted the code. hopefully you get it working. I’ll do edits if you find any problems)

    IList<Type> unnamedServices = new List<Type>();
    IDictionary<string, Type> namedServices = new Dictionary<string, Type>();
    
    ComponentDataDelegate registered = captureRegistrations(unnamedServices, namedServices);
    
    container.Kernel.ComponentRegistered += registered;
    
    // The method that captures the services
    private static ComponentDataDelegate captureRegistrations(
        IList<Type> unnamedServices, IDictionary<string, Type> namedServices)
    {
            return (key, handler) =>
                   {
                       if (handler.ComponentModel.Name == handler.ComponentModel.Implementation.FullName)
                       {
                           unnamedServices.Add(handler.Service);
                       }
                       else
                       {
                           namedServices.Add(key, handler.Service);
                       }
                   };
    }
    

    After that before I register services in code, I check if they already have been registered. I also created a base class that makes this more easy. This is an application configuration:

    public class ApplicationConfiguration : WindsorConfigurationSkeleton
    {
        internal static WindsorServiceLocator create()
        {
            var container = createWith(null, "components-config.xml", coreServices, caches, roles);
            return new WindsorServiceLocator(container);
        }
    
        internal static IEnumerable<IRegistration> coreServices()
        {
            yield return Component.For<ISystemClock>()
                .ImplementedBy<PreciseSystemClock>()
                .Parameters(Parameter.ForKey("synchronizePeriodSeconds").Eq("10"))
                .LifeStyle.Singleton;
    
            yield return Component.For<IMailService>()
                .ImplementedBy<MailQueueService>()
                .LifeStyle.Singleton;
        }
    
        internal static IEnumerable<IRegistration> caches()
        {
            yield return Component.For<IDataCache<ServiceAttributes>>()
                .ImplementedBy<NoDataCache<ServiceAttributes>>()
                .LifeStyle.Singleton;
    
            // ....
        }
    }
    

    The base class that does the wiring:
    (Logging is from Commons.Logging)

    public class WindsorConfigurationSkeleton
    {
        private static readonly ILog _log = LogManager.GetLogger(
            typeof(WindsorConfigurationSkeleton));
    
        internal static IWindsorContainer createWith(
            IRegistration[] customs, string configFile, params Func<IEnumerable<IRegistration>>[] methods)
        {
            IWindsorContainer container = new WindsorContainer();
            BugFix.Kernel = container.Kernel;
    
            container.AddFacility("factory.support", new FactorySupportFacility());
    
            IList<Type> unnamedServices = new List<Type>();
            IDictionary<string, Type> namedServices = new Dictionary<string, Type>();
    
            ComponentDataDelegate registered = captureRegistrations(unnamedServices, namedServices);
    
            container.Kernel.ComponentRegistered += registered;
    
            if (customs != null)
            {
                container.Register(customs);
            }
    
            if (configFile != null)
            {
                tryAddXmlConfig(container, configFile);
            }
    
            container.Kernel.ComponentRegistered -= registered;
    
            if (methods != null && methods.Length > 0)
            {
                container.Register(union(unnamedServices, namedServices, methods));
            }
    
            return container;
        }
    
        private static ComponentDataDelegate captureRegistrations(
            IList<Type> unnamedServices, IDictionary<string, Type> namedServices)
        {
            return (key, handler) =>
                   {
                       if (handler.ComponentModel.Name == handler.ComponentModel.Implementation.FullName)
                       {
                            var text = unnamedServices.Contains(handler.Service) ? "another" : "default";
                           _log.Info(
                               m => m(
                                        "Registered {2} service for {0} with {1}.",
                                        handler.Service.GetDisplayName(),
                                        handler.ComponentModel.Implementation.GetDisplayName(),
                                        text
                                        ));
    
                           unnamedServices.Add(handler.Service);
                       }
                       else
                       {
                            var text = namedServices.ContainsKey(key) ? "another" : "default";
                           _log.Info(
                               m => m(
                                        "Registered {3} service {0} with name '{1}' and {2}.",
                                        handler.ComponentModel.Service,
                                        handler.ComponentModel.Name,
                                        handler.ComponentModel.Implementation.GetDisplayName(),
                                        text
                                        ));
                           namedServices.Add(key, handler.Service);
                       }
                   };
        }
    
        protected static void tryAddXmlConfig(IWindsorContainer container, string filename)
        {
            var fi = Resources.GetFileFromResourceHierarchy(typeof(ApplicationContext).Namespace, filename);
            if ( fi == null ) {
                return;
            }
            var configFile = fi.FullName;
            var xd = immitateFluentApiDefaultIdBehaviour(configFile);
            container.Install(Configuration.FromXml(new StaticContentResource(xd.OuterXml)));
    
        }
    
        private static XmlDocument immitateFluentApiDefaultIdBehaviour(string configFile)
        {
            var xd = new XmlDocument();
            xd.Load(configFile);
    
            foreach (
                XmlElement component in
                    xd.SelectNodes("/configuration/components/component[@type and (not(@id) or @id = '')]"))
            {
                var type = Type.GetType(component.GetAttribute("type"), true);
                component.SetAttribute("id", type.FullName);
            }
    
            return xd;
        }
    
        private static IRegistration[] union(
            IList<Type> unnamed, IDictionary<string, Type> named, params Func<IEnumerable<IRegistration>>[] methods)
        {
            var all = new List<IRegistration>();
            foreach (var method in methods)
            {
                foreach (var registration in method())
                {
                    var registrationType = registration.GetType();
                    if (registrationType.IsGenericTypeOf(typeof(ComponentRegistration<>)))
                    {
                        var componentType = registrationType.GetGenericArgumentsFor(typeof(ComponentRegistration<>))[0];
    
                        var name = (string)registrationType.GetProperty("Name").GetValue(registration, null);
    
                        if (name != null)
                        {
                            if (named.ContainsKey(name))
                            {
                                _log.Debug(
                                    m => m("Skipped registering default named component {0}.", name));
                                continue;
                            }
                        }
                        else if (unnamed.Contains(componentType))
                        {
                            _log.Debug(
                                m => m("Skipped registering default component for type {0}.", componentType));
                            continue;
                        }
    
                        all.Add(registration);
                    }
                    else
                    {
                        all.Add(registration);
                    }
                }
            }
    
            return all.ToArray();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a function in a certain module that I want to redefine(mock) at
Want my FireFox at work to be in sync with my FireFox at my
I want to make an etag that matches what Apache produces. How does apache
I want to redefine the ToString() function in one of my classes. I wrote
I want to redefine the required attribute for a field in a clean method
I want to redefine NULL in my program such as #define MYNULL ((void*)0) But
I want to use a temp directory that will be unique to this build.
Every time that I want to do a Layout, I'm getting a black layout
Want to know what the stackoverflow community feels about the various free and non-free
I want to loop over the contents of a text file and do a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.