Does anyone knows how to workaround the fact Unity Container InjectionConstructor does not have any overload for Func<string>?
this.unityContainer
.RegisterType<IService1Client, Service1Client>()
.Configure<InjectedMembers>()
.ConfigureInjectionFor<Service1Client>(
new InjectionConstructor(() =>
this.unityContainer.Resolve<User>()
.SelectedDepartment
.ApplicationServerUrl
.ToString()));
Cheers,
You could use the InjectionFactory.
this.unityContainer.RegisterType<IService1Client>(
new InjectionFactory((ctr, type, name) =>
{
User user = this.unityContainer.Resolve<User>();
string url = user.SelectedDepartment.ApplicationServerUrl.ToString();
return new Service1Client(url);
}));
Think I found out the answer myself:
Func<string> GetApplicationServerUrl = () => {
return this.unityContainer.Resolve<User>()
.SelectedDepartment
.ApplicationServerUrl
.ToString();
};
this.unityContainer.RegisterType<IService1Client, Service1Client>()
.Configure<InjectedMembers>()
.ConfigureInjectionFor<Service1Client>(
new InjectionConstructor(GetApplicationServerUrl()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With