2

I have a service interface that uses generics. That interface has multiple implementations. Those implementations also use generics and provide multiple concrete components for the closed service interface. For (extremely overly simplified) example:

public interface IService<T1, T2> { }

public class ServiceImpl<T> : 
  IService<IDbConnection, T>,
  IService<DbConnection, T>,
  IService<SqlConnection, T> { }

Then having registration in Castle Windsor:

container.Register(Component
  .For<IService<SqlConnection, SomeOtherClass>>()
  .Named(NameHelper.GetName(typeof(SqlConnection), typeof(SomeOtherClass))
  .Forward<IService<DbConnection, SomeOtherClass>>()
  .Forward<IService<IDbConnection, SomeOtherClass>>()   
  .ImplementedBy<ServiceImpl<SomeOtherClass>>()
  .LifestyleTransient());

Is there any way to give alternate names to each of the Forward's? The problem can be solved, I'm guessing, by registering each Foward individually with its own name, but it would be nice to just be able to do something like:

.Forward<IService<DbConnection, SomeOtherClass>>(
    NameHelper.Getname(typeof(DbConnection), typeof(SomeOtherClass))

(Outside the scope of this simplified question and example, but I can probably also achieve the overall design goal using IGenericServiceStrategy and/or IGenericImplementationMatchingStrategy instead of registering each individual permutation, but I'm under time constraints so being able to just name the forwards individually would be great).

The code in question is using Castle Windsor v3.3.0.

Chrisgh
  • 1,016
  • 2
  • 10
  • 18

0 Answers0