예제 #1
0
        /// <inheritdoc />
        public IAspectRegistrationBuilder AddService(Type service, Func <IServiceProvider, object> factory,
                                                     ServiceLifetime serviceLifetime)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            var aspectConfiguration = new AspectConfiguration(new ServiceDescriptor(service, factory, serviceLifetime));

            AspectConfigurationProvider.AddEntry(aspectConfiguration);
            Services.Add(new ServiceDescriptor(service,
                                               serviceProvider => InvokeCreateFactory(serviceProvider, aspectConfiguration), serviceLifetime));
            return(this);
        }
예제 #2
0
        public IAspectRegistrationBuilder AddService(Type service, Type implementation,
                                                     ServiceLifetime serviceLifetime)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (implementation == null)
            {
                throw new ArgumentNullException(nameof(implementation));
            }
            if (!implementation.IsConcreteClass() || !service.IsAssignableFrom(implementation))
            {
                throw new ArgumentException(
                          $"The {nameof(implementation)} ({implementation.FullName}) must be a concrete class that implements the {nameof(service)} ({service.Name})");
            }

            var aspectConfiguration =
                new AspectConfiguration(ServiceDescriptor.Describe(service, implementation, serviceLifetime));

            RegisterAspectConfiguration(aspectConfiguration);
            AspectConfigurationProvider.AddEntry(aspectConfiguration);
            return(this);
        }