private static void Inject <TFilter>(IServiceInjector container, ICollection <object> injectedFilters, IEnumerable <TFilter> filters) where TFilter : class { foreach (TFilter filter in filters.Where(filter => IsFilterAttriute(filter) && !injectedFilters.Contains(filter))) { container.Inject(filter); injectedFilters.Add(filter); } }
public ServiceItem(Scope scope, Type mappingType, Type type, IServiceInjector injector, Func <IServiceInjector, object> factory = null) { Scope = scope; MappingType = mappingType; Type = type; _injector = injector; _factory = factory; }
public static void Inject(IServiceInjector container, FilterInfo filters) { ICollection <object> injectedFilters = new HashSet <object>(); Inject(container, injectedFilters, filters.AuthorizationFilters); Inject(container, injectedFilters, filters.ActionFilters); Inject(container, injectedFilters, filters.ResultFilters); Inject(container, injectedFilters, filters.ExceptionFilters); }
public ServiceItem(Scope scope, Type mappingType, Type type, IServiceInjector injector, object instance = null) { Scope = scope; MappingType = mappingType; Type = type; _injector = injector; _value = instance; _factory = _FindService; }
private static void Inject(IServiceInjector container, FilterInfo decoratedFilters) { ICollection <object> injectedFilters = new List <object>(); Inject(container, injectedFilters, decoratedFilters.AuthorizationFilters); Inject(container, injectedFilters, decoratedFilters.ActionFilters); Inject(container, injectedFilters, decoratedFilters.ResultFilters); Inject(container, injectedFilters, decoratedFilters.ExceptionFilters); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyContainer{TContainer, TConfigurator}" /> class. /// </summary> /// <param name="applicationConfiguration"> /// Configuration information for the application. /// </param> /// <param name="serviceInjector"> /// An object that adds service descriptors to the container. /// </param> /// <param name="configureAction"> /// An action that configures the container. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="applicationConfiguration" /> is <see langword="null" /> -or- <paramref name="serviceInjector" /> is /// <see langword="null" /> -or- <paramref name="configureAction" /> is <see langword="null" />. /// </exception> protected DependencyContainer(IConfiguration applicationConfiguration, IServiceInjector <TConfigurator> serviceInjector, Action <IConfiguration, TConfigurator> configureAction) : base(applicationConfiguration) { ConfigureAction = configureAction.RejectIf().IsNull(nameof(configureAction)); LazyReferenceManager = new Lazy <IReferenceManager>(() => new ReferenceManager(), LazyThreadSafetyMode.ExecutionAndPublication); LazyRootScope = new Lazy <IDependencyScope>(CreateRootScope, LazyThreadSafetyMode.ExecutionAndPublication); LazySourceContainer = new Lazy <TContainer>(BuildSourceContainer, LazyThreadSafetyMode.ExecutionAndPublication); ServiceInjector = serviceInjector.RejectIf().IsNull(nameof(serviceInjector)).TargetArgument; }
public ServiceContainer( IList <IService> list, IServiceResolver resolver, IServiceInjector injector, IServiceFactory singletonFactory, IServiceFactory transientFactory) { this.list = list; this.resolver = resolver; this.injector = injector; this.singletonFactory = singletonFactory; this.transientFactory = transientFactory; }
public BaseHandler(IServiceInjector serviceInjector) { if (serviceInjector.Configuration.IsNull()) { throw new ArgumentException("configuration not be null"); } if (serviceInjector.Mapper.IsNull()) { throw new ArgumentException("mapper not be null"); } _appConfig = serviceInjector.Configuration; _mapper = serviceInjector.Mapper; }
public static IServiceCollection ScanServices(this IServiceCollection services, IEnumerable <Assembly> assemblies, IServiceInjector serviceInjector = null) { var serviceTypes = assemblies.SelectMany(o => o.GetTypes()).Select(o => new { Type = o, Attributes = o.GetCustomAttributes <ServiceAttribute>().ToArray() }).Where(o => o.Attributes.Any()).ToArray(); foreach (var typeObj in serviceTypes) { foreach (var attr in typeObj.Attributes) { var useServiceInjector = serviceInjector?.RegisteredTypes.Contains(typeObj.Type) == true; var serviceDescriptor = attr.BuildServiceDescriptor(typeObj.Type, useServiceInjector); var isAlreadyRegistered = services.Any( x => x.ServiceType.FullName == serviceDescriptor.ServiceType.FullName); if (isAlreadyRegistered) { if (attr.ThrowIfExists) { throw new ServiceRegistrationException( $"This descriptor {serviceDescriptor.ImplementationType} must be the only " + $"registration for {serviceDescriptor.ServiceType.FullName}"); } if (attr.Replace) { services = services.Replace(serviceDescriptor); } else { services.Add(serviceDescriptor); } } else { services.Add(serviceDescriptor); } } } return(services); }
public ServiceBus(IServiceInjector injector) { _Injector = injector; }
///<summary> /// Default constructor ///</summary> ///<param name="serviceLocator"></param> public InjectableAttributeFilterProvider(IServiceInjector serviceLocator) { Injector = serviceLocator; }
internal DotNetNativeDependencyContainer(IConfiguration applicationConfiguration, IServiceInjector <ServiceCollection> serviceInjector, Action <IConfiguration, ServiceCollection> configureAction) : base(applicationConfiguration, serviceInjector, configureAction) { return; }
public AuthenticateVehicleCommandHandler(IVehicleRepository vehicleRepository, IServiceInjector serviceInjector) : base(serviceInjector) { _vehicleRepository = vehicleRepository; }
public GetLocationQueryHandler(ITrackingInfoRepository trackingInfoRepository, IServiceInjector serviceInjector) : base(serviceInjector) { _trackingInfoRepository = trackingInfoRepository; }
/// <summary> /// Creates a new dependency container. /// </summary> /// <param name="applicationConfiguration"> /// Configuration information for the application. /// </param> /// <param name="serviceInjector"> /// An object that injects service descriptors into a container configurator. /// </param> /// <param name="configureAction"> /// An action that configures the container. /// </param> /// <returns> /// A new dependency container. /// </returns> protected override IDependencyContainer CreateContainer(IConfiguration applicationConfiguration, IServiceInjector <ServiceCollection> serviceInjector, Action <IConfiguration, ServiceCollection> configureAction) => new DotNetNativeDependencyContainer(applicationConfiguration, serviceInjector, configureAction);
private object _FindService(IServiceInjector injector) { return(_bestMatchConstructor == null ? _findBestMatch() : _bestMatchConstructor.Invoke(_generateParameters(_bestMatchConstructor.GetParameters()))); }
public AddTrackInfoCommandHandler(ITrackingInfoRepository trackingInfoRepository, IServiceInjector serviceInjector) : base(serviceInjector) { _trackingInfoRepository = trackingInfoRepository; }
/// <summary> /// Initializes a new instance of the <see cref="BusinessObjectFactory" /> class. /// </summary> /// <param name="store">The store.</param> /// <param name="serviceInjector">The service injector.</param> public BusinessObjectFactory(IDataStore store, IServiceInjector serviceInjector) { Store = store; ServiceInjector = serviceInjector; }
/// <summary> /// Initializes a new instance of the <see cref="SimulatedDependecyContainer" /> class. /// </summary> /// <param name="applicationConfiguration"> /// Configuration information for the application. /// </param> /// <param name="configureAction"> /// An action that configures the container. /// </param> /// <param name="serviceInjector"> /// An object that adds service descriptors to the container. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="applicationConfiguration" /> is <see langword="null" /> -or- <paramref name="serviceInjector" /> is /// <see langword="null" /> -or- <paramref name="configureAction" /> is <see langword="null" />. /// </exception> public SimulatedDependecyContainer(IConfiguration applicationConfiguration, IServiceInjector <SimulatedSourceConfigurator> serviceInjector, Action <IConfiguration, SimulatedSourceConfigurator> configureAction) : base(applicationConfiguration, serviceInjector, configureAction) { return; }
public MockServiceProvider WithInjector <T>(IServiceInjector <T> serviceInjector) { _serviceDictionary[typeof(IServiceInjector <T>)] = () => serviceInjector; _serviceDictionary[typeof(T)] = () => serviceInjector.Service; return(this); }
public static IServiceCollection AddServiceInjector(this IServiceCollection services, IEnumerable <Assembly> assemblies, out IServiceInjector injector) { var concreteInjector = new ServiceInjector(); injector = concreteInjector; concreteInjector.Register(assemblies); return(services.AddSingleton(injector)); }
public GetCurrentLocationByVehicleIdQueryHandler(ITrackingInfoRepository trackingInfoRepository, IServiceInjector serviceInjector) : base(serviceInjector) { _trackingInfoRepository = trackingInfoRepository; }
/// <summary> /// Creates a new dependency container. /// </summary> /// <param name="applicationConfiguration"> /// Configuration information for the application. /// </param> /// <param name="serviceInjector"> /// An object that injects service descriptors into a container configurator. /// </param> /// <param name="configureAction"> /// An action that configures the container. /// </param> /// <returns> /// A new dependency container. /// </returns> protected override IDependencyContainer CreateContainer(IConfiguration applicationConfiguration, IServiceInjector <ContainerBuilder> serviceInjector, Action <IConfiguration, ContainerBuilder> configureAction) => new AutofacDependencyContainer(applicationConfiguration, serviceInjector, configureAction);
/// <summary> /// Initializes a new instance of the <see cref="CommonServiceBootStapper"/> class. /// </summary> protected CommonServiceBootStapper() { Locator = CreateServiceLocator(); Injector = CreateServiceInjector(); }
public RegisterVehicleCommandHandler(IVehicleRepository vehicleRepository, IServiceInjector serviceInjector) : base(serviceInjector) { _vehicleRepository = vehicleRepository; }
internal AutofacDependencyContainer(IConfiguration applicationConfiguration, IServiceInjector <ContainerBuilder> serviceInjector, Action <IConfiguration, ContainerBuilder> configureAction) : base(applicationConfiguration, serviceInjector, configureAction) { return; }
public ServiceItem(Scope scope, Type mappingType, Type type, IServiceInjector injector) : this(scope, mappingType, type, injector, default(object)) { }