/// <summary>
        ///     Creates a non-generic binding.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <returns></returns>
        public IBindingNonGeneric Bind(Type serviceType)
        {
            var bindingConfiguration = new BindingConfigurationForCode(serviceType);

            AddBinding(bindingConfiguration);
            return(new BindingNonGeneric(this, bindingConfiguration));
        }
        /// <summary>
        ///     Creates a generic binding.
        /// </summary>
        /// <typeparam name="TService">The type of the service.</typeparam>
        /// <returns></returns>
        public IBindingGeneric <TService> Bind <TService>()
        {
            var bindingConfiguration = new BindingConfigurationForCode(typeof(TService));

            var binding = new BindingGeneric <TService>(this, bindingConfiguration);

            AddBinding(bindingConfiguration);
            return(binding);
        }
        private void AddBinding(BindingConfigurationForCode bindingConfiguration)
        {
            List <BindingConfigurationForCode> bindingConfigurations;

            if (!_serviceTypeToBindingConfigurationsMap.TryGetValue(bindingConfiguration.ServiceType, out bindingConfigurations))
            {
                bindingConfigurations = new List <BindingConfigurationForCode>();
            }
            else
            {
                LogHelper.Context.Log.WarnFormat("A binding for service type '{0}' is aadded multiple times. This might result in unexpected behaviour. If the service should be bound to multiple implementations, use '{1}' in '{2}' or the similar member in generic type.",
                                                 bindingConfiguration.ServiceType.FullName, nameof(IBindingImplementationNonGeneric.Service), typeof(IBindingImplementationNonGeneric));
            }

            bindingConfigurations.Add(bindingConfiguration);
            BindingConfigurationAdded?.Invoke(this, new BindingConfigurationAddedEventArgs(bindingConfiguration));
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindingGeneric{TService}" /> class.
 /// </summary>
 /// <param name="serviceRegistrationBuilder">The service registration builder.</param>
 /// <param name="bindingConfiguration">The binding configuration.</param>
 public BindingGeneric([NotNull] IServiceRegistrationBuilder serviceRegistrationBuilder,
                       [NotNull] BindingConfigurationForCode bindingConfiguration) : base(serviceRegistrationBuilder, bindingConfiguration)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 ///  Initializes a new instance of the <see cref="Binding" /> class.
 /// </summary>
 /// <param name="serviceRegistrationBuilder">The service registration builder.</param>
 /// <param name="bindingConfiguration">The binding configuration.</param>
 public Binding([NotNull] IServiceRegistrationBuilder serviceRegistrationBuilder, [NotNull] BindingConfigurationForCode bindingConfiguration)
 {
     ServiceRegistrationBuilder = serviceRegistrationBuilder;
     BindingConfiguration       = bindingConfiguration;
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindingConfigurationAddedEventArgs" /> class.
 /// </summary>
 /// <param name="bindingConfiguration">The binding configuration.</param>
 public BindingConfigurationAddedEventArgs([NotNull] BindingConfigurationForCode bindingConfiguration)
 {
     BindingConfiguration = bindingConfiguration;
 }