コード例 #1
0
        /// <summary>
        /// Adds all operation handlers from the assembly.
        /// </summary>
        /// <param name="servicesBuilder">The builder.</param>
        /// <param name="assembly">The assembly. If not provided, <see cref="Assembly.GetCallingAssembly"/> is used.</param>
        /// <returns>The builder.</returns>
        public static GybsServicesBuilder AddOperationHandlers(this GybsServicesBuilder servicesBuilder, Assembly?assembly = null)
        {
            var serviceCollection = ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance;

            serviceCollection.AddTypesImplementingInterfaceFromAssembly(typeof(IOperationHandler <>), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Transient);
            serviceCollection.AddTypesImplementingInterfaceFromAssembly(typeof(IOperationHandler <,>), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Transient);

            return(servicesBuilder);
        }
コード例 #2
0
        /// <summary>
        /// Adds all types marked with dependency attributes to the service collection.
        /// </summary>
        /// <param name="servicesBuilder">The builder.</param>
        /// <param name="assembly">The assembly. If not provided, <see cref="Assembly.GetCallingAssembly"/> is used.</param>
        public static GybsServicesBuilder AddAttributeServices(this GybsServicesBuilder servicesBuilder, Assembly?assembly = default)
        {
            var serviceCollection = ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance;

            serviceCollection.AddTypesWithAttributeFromAssembly(typeof(SingletonServiceAttribute), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Singleton);
            serviceCollection.AddTypesWithAttributeFromAssembly(typeof(ScopedServiceAttribute), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Scoped);
            serviceCollection.AddTypesWithAttributeFromAssembly(typeof(TransientServiceAttribute), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Transient);

            return(servicesBuilder);
        }
コード例 #3
0
        /// <summary>
        /// Adds all types implementing one of the dependency injection services to the service collection.
        /// </summary>
        /// <param name="servicesBuilder">The builder.</param>
        /// <param name="assembly">The assembly. If not provided, <see cref="Assembly.GetCallingAssembly"/> is used.</param>
        public static GybsServicesBuilder AddInterfaceServices(this GybsServicesBuilder servicesBuilder, Assembly?assembly = default)
        {
            var serviceCollection = ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance;

            serviceCollection.AddTypesImplementingInterfaceFromAssembly(typeof(ISingletonService), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Singleton);
            serviceCollection.AddTypesImplementingInterfaceFromAssembly(typeof(IScopedService), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Scoped);
            serviceCollection.AddTypesImplementingInterfaceFromAssembly(typeof(ITransientService), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Transient);

            return(servicesBuilder);
        }
コード例 #4
0
        /// <summary>
        /// Adds a <see cref="IValidator"/> and all implementations of <see cref="IValidationRule{TValidationData}"/> which allows to aggregate validation rules.
        /// </summary>
        /// <param name="servicesBuilder">The builder.</param>
        /// <param name="assembly">The assembly. If not provided, <see cref="Assembly.GetCallingAssembly"/> is used.</param>
        /// <returns>The builder.</returns>
        public static GybsServicesBuilder AddValidation(this GybsServicesBuilder servicesBuilder, Assembly?assembly = null)
        {
            var serviceCollection = ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance;

            serviceCollection.TryAddTransient <IValidator, Validator>();

            serviceCollection.AddTypesImplementingInterfaceFromAssembly(
                typeof(IValidationRule <>),
                assembly ?? Assembly.GetCallingAssembly(),
                ServiceLifetime.Transient);

            return(servicesBuilder);
        }
コード例 #5
0
 /// <summary>
 /// Adds <see cref="IRepository{TEntity}"/> implementations from the assembly.
 /// </summary>
 /// <param name="servicesBuilder">The builder.</param>
 /// <param name="serviceLifetime">The lifetime of registered service.</param>
 /// <param name="assembly">The assembly. If not provided, <see cref="Assembly.GetCallingAssembly"/> is used.</param>
 /// <returns>The builder.</returns>
 public static GybsServicesBuilder AddRepositories(this GybsServicesBuilder servicesBuilder, ServiceLifetime serviceLifetime, Assembly?assembly = null)
 {
     ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance
     .AddTypesImplementingInterfaceFromAssembly(typeof(IRepository <>), assembly ?? Assembly.GetCallingAssembly(), serviceLifetime);
     return(servicesBuilder);
 }
コード例 #6
0
 /// <summary>
 /// Adds all operation initializers from the assembly which are used by factory to initialize operations.
 /// </summary>
 /// <param name="servicesBuilder">The builder.</param>
 /// <param name="assembly">The assembly. If not provided, <see cref="Assembly.GetCallingAssembly"/> is used.</param>
 /// <returns>The builder.</returns>
 public static GybsServicesBuilder AddOperationInitializersForFactory(this GybsServicesBuilder servicesBuilder, Assembly?assembly = null)
 {
     ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance
     .AddTypesImplementingInterfaceFromAssembly(typeof(IOperationInitializer), assembly ?? Assembly.GetCallingAssembly(), ServiceLifetime.Scoped);
     return(servicesBuilder);
 }
コード例 #7
0
 /// <summary>
 /// Adds a <see cref="IOperationFactory"/> which allows to create and handle operations via <see cref="IOperationBus"/>.
 /// </summary>
 /// <param name="servicesBuilder">The builder.</param>
 /// <returns>The builder.</returns>
 public static GybsServicesBuilder AddOperationFactory(this GybsServicesBuilder servicesBuilder)
 {
     ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance
     .TryAddScoped <IOperationFactory, OperationFactory>();
     return(servicesBuilder);
 }
コード例 #8
0
 /// <summary>
 /// Adds a <see cref="IOperationBus"/> which handles operations by resolving a handler from service provider.
 /// </summary>
 /// <param name="servicesBuilder">The builder.</param>
 /// <returns>The builder.</returns>
 public static GybsServicesBuilder AddServiceProviderOperationBus(this GybsServicesBuilder servicesBuilder)
 {
     ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance
     .TryAddScoped <IOperationBus, ServiceProviderOperationBus>();
     return(servicesBuilder);
 }
コード例 #9
0
 /// <summary>
 /// Adds the singleton in-memory implementation of <see cref="IEventBus"/>.
 /// </summary>
 /// <param name="servicesBuilder">The builder.</param>
 /// <returns>The builder.</returns>
 public static GybsServicesBuilder AddInMemoryEventBus(this GybsServicesBuilder servicesBuilder)
 {
     ((IInfrastructure <IServiceCollection>)servicesBuilder).Instance
     .TryAddSingleton <IEventBus, InMemoryEventBus>();
     return(servicesBuilder);
 }