/// <summary>
        ///     Bind service <typeparamref name="TService" /> to implementation <typeparamref name="TImplementation" />.
        /// </summary>
        /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
        /// <returns>
        ///     Returns <see cref="T:IoC.Configuration.DiContainer.BindingsForCode.IBindingImplementationGeneric`2" />
        /// </returns>
        public IBindingImplementationGeneric <TService, TImplementation> To <TImplementation>() where TImplementation : TService
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateTypeBasedImplementationConfiguration(BindingConfiguration.ServiceType, typeof(TImplementation));

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationGeneric <TService, TImplementation>(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
        /// <summary>
        ///     Bind service <typeparamref name="TService" /> to itself.
        /// </summary>
        /// <returns>
        ///     Returns <see cref="T:IoC.Configuration.DiContainer.BindingsForCode.IBindingImplementationGeneric`2" />
        /// </returns>
        public IBindingImplementationGeneric <TService, TService> ToSelf()
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateSelfImplementationConfiguration(BindingConfiguration.ServiceType);

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationGeneric <TService, TService>(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
        public BindingImplementationNonGeneric To(Func <IDiContainer, object> resolverFunc)
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateDelegateBasedImplementationConfiguration(BindingConfiguration.ServiceType, resolverFunc);

            BindingConfiguration.AddImplementation(bindingImplementationConfiguration);
            return(new BindingImplementationNonGeneric(ServiceRegistrationBuilder, bindingImplementationConfiguration, this));
        }
        public BindingImplementationNonGeneric To(Type implementationType)
        {
            var bindingImplementationConfiguration = BindingImplementationConfigurationForCode.CreateTypeBasedImplementationConfiguration(BindingConfiguration.ServiceType, implementationType);

            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));
        }
示例#6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindingImplementationNonGeneric" /> class.
 /// </summary>
 /// <param name="serviceRegistrationBuilder">The service registration builder.</param>
 /// <param name="bindingImplementationConfiguration">The binding implementation configuration.</param>
 /// <param name="serviceBinding">The service binding.</param>
 public BindingImplementationNonGeneric([NotNull] IServiceRegistrationBuilder serviceRegistrationBuilder,
                                        [NotNull] BindingImplementationConfigurationForCode bindingImplementationConfiguration,
                                        [NotNull] BindingNonGeneric serviceBinding) : base(serviceRegistrationBuilder, bindingImplementationConfiguration)
 {
     Service = serviceBinding;
 }
示例#7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindingImplementation" /> class.
 /// </summary>
 /// <param name="serviceRegistrationBuilder">The service registration builder.</param>
 /// <param name="bindingImplementationConfiguration">The binding implementation configuration.</param>
 public BindingImplementation([NotNull] IServiceRegistrationBuilder serviceRegistrationBuilder,
                              [NotNull] BindingImplementationConfigurationForCode bindingImplementationConfiguration)
 {
     ServiceRegistrationBuilder         = serviceRegistrationBuilder;
     BindingImplementationConfiguration = bindingImplementationConfiguration;
 }