There is a typed factory:
public interface IDataProviderFactory { IDataProvider Create(ConfigurationItem configurationItem); void Release(IDataProvider dataProvider); }
There are several implementations of IDataProvider
- Some implementations are depend on ICalculator
- There are several implementations of ICalculator
There is a configuration class:
public class ConfigurationItem { public CalculatorsEnum CalculatorsEnum { get; set; } public DataPriversEnum DataPriversEnum { get; set; } }
When I am trying to call the factory's method Create, Windsor is trying to resolve the IDataProvider's dependencies, which is ICalculator.
Here I need the container to use the information from the original parameter so that to understand which version of the ICalculator to use.
Update
I would like to add some details:
- There is a class where I use IDataProviderFactory. There I control the lifecycle of the IDataProviders, I create and destroy them from time to time using the factory. So at this level I don't want to know anything about the IDataProvider implementation- there might be the DataProvider without a calculator.
- At the beginning I had my own implementation of the IDataProviderFactory, where I could resolve ICalculator and inject it into the DataProvider. But when it comes to the recycling, I was disposing the DataProvider, but it appeared that disposing is not enough in case with Windsor when you manually resolve something, you need explicitly release it.
Possible solutions:
- I still can do all this manually, but most likely I will break the beauty with some casting or so.
- I can inject the typed factory of the Calculators into the DataProviders implementation, if needed, and control the lifecycle of the Calculator there. For example: I create the DataProvider with my factory and then I don't need it, I release it, the container will call the dispose of the DataProvider where I will release the Calculator with its own factory.
- Windsor way?
Constructor parameters are only passed to the constructor of the top level service being resolved. This is by design.
The recommended solution would be to make a factory that resolves both ICalculator and IDataProvider. When resolving you would explicitly resolve ICalculator and then pass that into the factory function for IDataProvider.
See this question for further discussion.
Update
Yes every Resolve should have a matching Release, and this is true whether using factories or the container directly.
It would only be speculation to suggest what "the Windsor way" of addressing your particular scenario might be.
Windsor provides a number of different ways of specifying inline dependencies. See here for further details. Generally the methods outlined are preferable to using factories etc. because the resolving/releasing is managed by the container.