The following code is for demo purposes only.
Lets say i have 2 components (businessService, and dataService), and a UI class.
UI class needs a business service, businessService needs a dataService, and dataService relies on a connectionString.
Form the UI class i need to resolve the business service, so i am writing the below code:
var service = container.Resolve<BusinessService>(new { dependancy = "con string 123" }));
notice that dependancy is the connectionString constructor parameter.
But the above code is not working, saying that dataService expecting dependancy which was not satisified.
Can't create component 'dataService' as it has dependencies to be satisfied. dataService is waiting for the following dependencies:
Keys (components with specific keys) - dependancy which was not registered.
So as a workaround i am doing this:
var service = container.Resolve<BusinessService>(new { dataService = container.Resolve<IDataService>(new { dependancy = "123" }) });
But from design, coding style and many perspectives this is not a good way of doing it.
So please if you can advise why its not working in the simple way or you have a better workaround please share.