This repository has been archived by the owner. It is now read-only.

Castle Windsor

hmemcpy edited this page Jun 8, 2012 · 32 revisions

Castle Windsor supports registrations provided by a Fluent API and XML configuration. Agent Mulder plugin currently has a limited support for the Fluent API only.

The following registration patterns are currently supported (via IWindsorContainer.Register(params IRegistration[]) method, directly on the WindsorContainer instance or via a Windsor Installer.

Manual registration

Manual (or one-by-one) registration is done via the Castle.MicroKernel.Registration.Component class. The only methods Agent Mulder plugin inspects are Component.For and ImplementedBy, other methods are currently ignored.

  • Component.For<IFoo>().ImplementedBy<Foo>() - matches the concrete type Foo
  • Component.For<Foo>() - matches the concrete type Foo
  • Component.For<IFoo>() - matches IFoo

And their non-generic variants:

  • Component.For(typeof(IFoo)).ImplementedBy(typeof(Foo))
  • Component.For(typeof(Foo))
  • Component.For(typeof(IFoo))

Open generic types are supported using the non-generic overloads:

  • Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NHRepository<>))

Convention-based registration

In addition to registering the types one-by-one, Agent Mulder plugin supports analyzing convention-based registration.

  • AllTypes, Classes and Types
  • From(typeof(Foo), typeof(Bar)) - matches Foo and Bar
  • FromThisAssembly - adds an assembly constraint for the assembly (or module) in which registration takes place.
  • FromAssembly - currently supports Assembly.GetExecutingAssembly() and typeof(Foo).Assembly. Other assembly sources, including local variables are currently not supported.
  • FromAssemblyContaining - both generic and non generic variants

Additional filtering then can be performed using:

  • BasedOn<IFoo>() - will only select those types that are based on IFoo from the above descriptor
  • BasedOn(typeof(IFoo)) - the non generic variant of the above
  • InNamespace(string, bool) - matches types with the specified namespace (or starting with a specified namespace)
  • InSameNamespaceAs<IFoo>(bool) - matches types based on the specified generic parameter namespace (or starting with that namespace)
  • InSameNamespaceAs(Type, bool) - same as the generic variant, takes an optional boolean for subnamespaces (i.e. starting with the type's namespace)

Note: Currently, only direct typeof(T) and true/false values supported for the argument, not local variables, e.g.:



Not supported:

bool includeSubnamspaces = true;
  • Where - currently supported are only predicates generated with the Component static methods:
  • Component.IsInNamespace(string, boolean) - matches types with the specified namespace (or starting with a specified namespace)
  • Component.HasAttribute<T>(Type) - matches types that are decorated with an attribute T. Note: currently supported only as method group, i.e.: Where(Component.HasAttribute<MyAttribute>)

Not (yet) supported

  • FromAssembly - see above
  • FromAssemblyNamed
  • IncludeNonPublicTypes
  • Pick
  • Where - see above
  • Component.HasAttribute<T>(Predicate<T>)
  • WithService*
  • If/Unless
  • AsFactory() - how would you highlight a factory interface with no impl?