Search code examples
c#.netcastle-windsor

Does Castle Windsor have a naming convention to judge lifestyle automagically?


Though the question seems a bit weird. I am still riddling around in a new project I happen to join.

That project intensively uses Windsor Castle IoC. Inspecting the container after initialization tells me that some implementations have been registered as LifeStyle.Transient and others have LifeStyle.Singleton amongst others. Their custom bootstrapping code searches assemblies and does convention based registration but mentions nothing about Lifestyle. So how comes the registered components differ in lifestyle?

Does Castle Windsor have some magic naming convention?

for example: The pair IFooManager and FooManager would become a singleton, while IFoo and Foo would get transient life style.... (just due to *Manager).

As comments asked for it, this is the core registration that is executed in a loop over all /somehow enumerated/ assemblies:

                    var assembly = Assembly.LoadFrom(fileName);
                    container.Register(Classes.FromAssembly(assembly).Pick()
                        .If(t => TypeIsInNamespaces(includeNamespaces, t) && GetInterfacesOfType(t, includeNamespaces).Any())
                        .WithService.Select((t, baseT) => GetInterfacesOfType(t, includeNamespaces)).Configure(c => c.Named(GetName(c.Implementation))));

Solution

  • To answer your question as it is asked (because it can be answered) - no there is no way magic naming convention for Castle Windsor to imply lifestyle.