public BindingImplementationNonGeneric To(Func <IDiContainer, object> resolverFunc) { var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateDelegateBasedImplementationConfiguration(BindingConfiguration.ServiceType, resolverFunc); BindingConfiguration.AddImplementation(bindingImplementationConfiguration); return(new BindingImplementationNonGeneric(ServiceRegistrationBuilder, bindingImplementationConfiguration, this)); }
/// <summary> /// Bind service <typeparamref name="TService" /> to the result of function call <paramref name="resolverFunc" />( /// <see cref="T:IoC.Configuration.DiContainer.IDiContainer" />). /// TImplementation should be either <typeparamref name="TService" />, or a type that implements or derives from /// <typeparamref name="TService" />. /// Note, we can use value of <typeparamref name="TService" /> for <typeparamref name="TImplementation" /> not to /// restrict what the function /// <paramref name="resolverFunc" /> returns. In other words to enforce that the implementation returns /// <typeparamref name="TService" /> /// or a subclass or implementation of <typeparamref name="TService" />. /// </summary> /// <typeparam name="TImplementation">The type of the implementation.</typeparam> /// <param name="resolverFunc">The resolver function.</param> /// <returns> /// Returns <see cref="T:IoC.Configuration.DiContainer.BindingsForCode.IBindingImplementationGeneric`2" /> /// </returns> public IBindingImplementationGeneric <TService, TImplementation> To <TImplementation>(Func <IDiContainer, TImplementation> resolverFunc) where TImplementation : TService { var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateDelegateBasedImplementationConfiguration(BindingConfiguration.ServiceType, typeResolver => resolverFunc(typeResolver)); BindingConfiguration.AddImplementation(bindingImplementationConfiguration); return(new BindingImplementationGeneric <TService, TImplementation>(ServiceRegistrationBuilder, bindingImplementationConfiguration, this)); }