views:

59

answers:

1

I did the following:

    container.Register(Component.For<Dictionary<string, string>>()
                            .Instance(ServiceDictionaryInstance)
                            .Named("serviceDictionary"));

The class consumes the component is:

 public class BusinessService : IDecisionFilter
 {
     private readonly Dictionary<string, string> _ServiceDictionary;

  public BusinessService(IOtherInterface otherService, Dictionary<string, string> serviceDictionary)
  {
                    _OtherService = otherService,
      _ServiceDictionary = serviceDictionary;
  }
    }

Then Castle can't resolve the Dictionary component:

Failed: NotImplementedException The method or operation is not implemented. Failed: at Castle.MicroKernel.SubSystems.Conversion.GenericDictionaryConverter.PerformConversion(String value, Type targetType)

But if I create another class:

public class DictiornayType : Dictionary<string, string>
{ 
}

in place of the original Dictionary, everything resolved correctly.

Does this have anything to do with generic type?

Please advise.

+1  A: 

The thing is, a dictionary is not really a component/service. It's rather a parameter to some component/service. So you can just remove the dictionary registration and pass the dictionary instance as a parameter to the BusinessService component in its registration:

container.Register(Component.For<IDecisionFilter>()
                            .ImplementedBy<BusinessService>()
                            .DependsOn(new {
                                serviceDictionary = ServiceDictionaryInstance
                            }));

There is some talk about removing this difference between parameters and services for a future version of Windsor.

Mauricio Scheffer