0
votes

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))));
3
We would need to see the bootstrap code you're referring to. It's one thing if it searches the assemblies for interfaces and implemenations. It's another if it's searching the assemblies for classes implementing IWindsorInstaller. In that second scenario there would be a class in the assembly that registers dependencies and specifies lifestyles. Does the bootstrap code contain Install?Scott Hannen
See my own-answer below - which states what happened in my case.Robetto

3 Answers

2
votes

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.

1
votes

The best way to handle that is to partition your registration into Installers and use registration by convention to explicitly register certain groups of components with your desired configuration.

For example:

container.Register(Classes.FromThisAssembly()
    .InSameNamespaceAs<FooManager>()
    .WithService.DefaultInterfaces()
    .LifestyleTransient());

That way it's explicit and clear what is happening.

0
votes

So, I finally came across a place which explains the behavior.

So answer: No, Windsor Castle has no automagic lifestyle infer logic.

The reason in my case is:

They do use these Windsor Castle attributes that one can spread over implementations (components) to state their life style:

/// <summary>
/// Message Box factory.
/// </summary>
[Singleton]
public class MessageBoxFact : IMessageBoxFact
{

or

[Transient]