Exemplo n.º 1
0
        public static LinFxBuilder AddRabbitMq(this LinFxBuilder builder, Action <RabbitMqOptions> optionsAction)
        {
            Check.NotNull(builder, nameof(builder));
            Check.NotNull(optionsAction, nameof(optionsAction));

            var options = new RabbitMqOptions();

            optionsAction?.Invoke(options);
            builder.Services.Configure(optionsAction);

            builder.Services.AddSingleton(sp =>
            {
                return(new ConnectionFactoryWrapper(new ConnectionConfiguration
                {
                    Host = options.Host,
                    UserName = options.UserName,
                    Password = options.Password,
                }));
            });

            builder.Services
            .AddSingleton <IConnectionPool, DefaultConnectionPool>()
            .AddSingleton <IChannelPool, DefaultChannelPool>()
            .AddSingleton <IConsumerFactory, RabbitMqConsumerFactory>()
            .AddSingleton <IRabbitMqSerializer, DefaultRabbitMqSerializer>()
            .AddTransient <RabbitMqConsumer>();

            return(builder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds authorization services to the specified <see cref="LinFxBuilder" />.
        /// </summary>
        /// <param name="builder">The current <see cref="LinFxBuilder" /> instance. </param>
        /// <param name="configure">An action delegate to configure the provided <see cref="AuthorizationOptions"/>.</param>
        /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
        public static LinFxBuilder AddAuthorization([NotNull] this LinFxBuilder builder, [NotNull] Action <AuthorizationOptions> configure)
        {
            var options = new AuthorizationOptions();

            configure?.Invoke(options);

            builder.Services.Configure(configure);
            builder.Services.Configure <PermissionOptions>(o =>
            {
                options.Permissions.DefinitionProviders.ToList().ForEach(item =>
                {
                    o.DefinitionProviders.Add(item);
                });

                options.Permissions.ValueProviders.ToList().ForEach(item =>
                {
                    o.ValueProviders.Add(item);
                });
            });

            //builder.Services.AddAuthorization();
            //builder.Services.AddAuthorizationCore();
            builder.Services.AddSingleton <IPermissionChecker, PermissionChecker>();
            builder.Services.AddSingleton <IPermissionDefinitionContext, PermissionDefinitionContext>();
            builder.Services.AddSingleton <IPermissionDefinitionManager, PermissionDefinitionManager>();
            //fx.Services.TryAdd(ServiceDescriptor.Transient<IAuthorizationPolicyProvider, LinFx.Security.Authorization.DefaultAuthorizationPolicyProvider>());
            builder.Services.AddSingleton <IAuthorizationHandler, PermissionAuthorizationHandler>();

            return(builder);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 注册程序集下实现依赖注入接口的类型
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="assembly"></param>
        public static LinFxBuilder AddAssembly(this LinFxBuilder builder, Assembly assembly)
        {
            var types = assembly.GetTypes().Where(type => type != null && type.IsClass && !type.IsAbstract && !type.IsGenericType).ToArray();

            AddTypes(builder.Services, types);
            return(builder);
        }
        public static LinFxBuilder AddLinFx(this IServiceCollection services)
        {
            var builder = new LinFxBuilder(services);

            builder.Services.AddLogging();
            return(builder);
        }
 public static LinFxBuilder AddTenantManagement(this LinFxBuilder builder, Action <MultiTenancyOptions> optionsAction = default)
 {
     builder.AddMultiTenancy(optionsAction);
     builder.Services.AddTransient <ITenantStore, TenantStore>();
     builder.Services.AddTransient <ITenantService, TenantService>();
     return(builder);
 }
Exemplo n.º 6
0
 public static LinFxBuilder AddDbContext <TContext>([NotNull] this LinFxBuilder builder,
                                                    Action <DbContextOptionsBuilder> optionsAction = null,
                                                    ServiceLifetime contextLifetime = ServiceLifetime.Scoped,
                                                    ServiceLifetime optionsLifetime = ServiceLifetime.Scoped) where TContext : DbContext
 {
     builder.Services.AddDbContext <TContext>(optionsAction, contextLifetime, optionsLifetime);
     return(builder);
 }
Exemplo n.º 7
0
 public static LinFxBuilder AddEventStores(
     [NotNull] this LinFxBuilder builder,
     [NotNull] Action <EventStoreOptionsBuilder> optionsAction)
 => AddEventStores(
     builder,
     optionsAction == null
             ? (Action <IServiceProvider, EventStoreOptionsBuilder>)null
             : (p, b) => optionsAction.Invoke(b));
Exemplo n.º 8
0
        public static LinFxBuilder AddNavigation(this LinFxBuilder builder, Action <NavigationOptions> optionsAction)
        {
            builder.Services.Configure(optionsAction);

            builder.Services
            .AddSingleton <IMenuManager, MenuManager>();

            return(builder);
        }
        /// <summary>
        /// 账号模块
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static LinFxBuilder AddAccountExtensions(this LinFxBuilder services)
        {
            services.Services
            .AddDistributedMemoryCache()
            .AddSingleton <AuthenticationConfig>()
            .AddTransient <ITokenService, TokenService>()
            .AddTransient <IAccountService, AccountService>();

            return(services);
        }
        public static LinFxBuilder AddMongoDBContext(this LinFxBuilder builder, Action <MongoDbOptions> optionsAction)
        {
            Check.NotNull(builder, nameof(builder));
            Check.NotNull(optionsAction, nameof(optionsAction));

            builder.Services.Configure(optionsAction);
            builder.Services.AddSingleton <MongoDbContext>();

            return(builder);
        }
Exemplo n.º 11
0
        //public static ILinFxBuilder AddEventBus(
        //    [NotNull] this ILinFxBuilder builder,
        //    [NotNull] Action<EventBusOptions> optionsAction)
        //{
        //    Check.NotNull(builder, nameof(builder));
        //    Check.NotNull(optionsAction, nameof(optionsAction));

        //    var optionsBuilder = new EventBusOptions();
        //    optionsAction?.Invoke(optionsBuilder);

        //    return builder;
        //}

        public static LinFxBuilder AddEventBus(this LinFxBuilder fx, Action <EventBusOptionsBuilder> optionsAction)
        {
            var options        = new EventBusOptions();
            var optionsBuilder = new EventBusOptionsBuilder(fx, options);

            optionsAction?.Invoke(optionsBuilder);

            fx.Services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();

            return(fx);
        }
Exemplo n.º 12
0
        public static void UseRabbitMQ(
            [NotNull] this EventBusOptions options,
            [NotNull] LinFxBuilder fx,
            [NotNull] Action <RabbitMqOptions> optionsAction)
        {
            Check.NotNull(options, nameof(options));
            Check.NotNull(optionsAction, nameof(optionsAction));
            Check.NotNull(fx, nameof(fx));

            fx.AddRabbitMQ(optionsAction);
            fx.Services.AddSingleton <IEventBus, RabbitMqDistributedEventBus>();
        }
Exemplo n.º 13
0
 public static LinFxBuilder AddDistributedMemoryCache(this LinFxBuilder builder, Action <MemoryDistributedCacheOptions> setupAction = default)
 {
     if (setupAction == default)
     {
         builder.Services.AddDistributedMemoryCache();
     }
     else
     {
         builder.Services.AddDistributedMemoryCache(setupAction);
     }
     return(builder);
 }
Exemplo n.º 14
0
        //public static ILinFxBuilder AddEventBus(
        //    [NotNull] this ILinFxBuilder builder,
        //    [NotNull] Action<EventBusOptions> optionsAction)
        //{
        //    Check.NotNull(builder, nameof(builder));
        //    Check.NotNull(optionsAction, nameof(optionsAction));

        //    var optionsBuilder = new EventBusOptions();
        //    optionsAction?.Invoke(optionsBuilder);

        //    return builder;
        //}

        public static LinFxBuilder AddEventBus(
            [NotNull] this LinFxBuilder builder,
            [NotNull] Action <EventBusOptionsBuilder> optionsAction)
        {
            var options        = new EventBusOptions();
            var optionsBuilder = new EventBusOptionsBuilder(builder, options);

            optionsAction?.Invoke(optionsBuilder);

            builder.Services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();

            return(builder);
        }
Exemplo n.º 15
0
        public static LinFxBuilder AddMultiTenancy(this LinFxBuilder builder, Action <MultiTenancyOptions> optionsAction = default)
        {
            if (optionsAction != null)
            {
                builder.Services.Configure(optionsAction);
            }

            builder.Services.AddTransient <ITenantResolver, TenantResolver>();
            builder.Services.AddTransient <ICurrentTenant, CurrentTenant>();
            builder.Services.AddSingleton <ICurrentTenantAccessor, CurrentTenantAccessor>();
            builder.Services.AddSingleton <ITenantResolveResultAccessor, HttpContextTenantResolveResultAccessor>();
            return(builder);
        }
        /// <summary>
        /// AddLinFx Code
        /// </summary>
        /// <param name="services"></param>
        /// <param name="optionsAction"></param>
        /// <returns></returns>
        public static LinFxBuilder AddLinFx(this IServiceCollection services, Action <LinFxOptions> optionsAction = default)
        {
            if (optionsAction != null)
            {
                services.Configure(optionsAction);
            }

            var builder = new LinFxBuilder(services);

            builder.AddAssembly(typeof(LinFxModule).Assembly);
            builder.Services.AddOptions();
            builder.Services.AddLogging();
            return(builder);
        }
Exemplo n.º 17
0
        public static LinFxBuilder AddPermissionManagement(this LinFxBuilder builder)
        {
            builder.Services.AddTransient <IPermissionService, PermissionService>();
            builder.Services.AddSingleton <PermissionManager>();

            //services.AddHttpContextAccessor();
            //services.AddTransient<IHttpContextPrincipalAccessor, HttpContextPrincipalAccessor>();

            //services.AddSingleton<IPermissionChecker, PermissionChecker>();
            builder.Services.AddSingleton <IPermissionDefinitionContext, PermissionDefinitionContext>();
            builder.Services.AddSingleton <IPermissionDefinitionManager, PermissionDefinitionManager>();

            return(builder);
        }
        public static LinFxBuilder AddElasticsearch(this LinFxBuilder builder, Action <ElasticsearchOptions> optionsAction)
        {
            var options = new ElasticsearchOptions();

            optionsAction?.Invoke(options);

            var node     = new Uri(options.Host);
            var settings = new ConnectionSettings(node).DefaultIndex(options.Index);
            var client   = new ElasticClient(settings);

            builder.Services.Add(ServiceDescriptor.Singleton <IElasticClient>(client));

            return(builder);
        }
Exemplo n.º 19
0
        public static LinFxBuilder AddEventStores(
            [NotNull] this LinFxBuilder builder,
            [NotNull] Action <IServiceProvider, EventStoreOptionsBuilder> optionsAction,
            ServiceLifetime optionsLifetime = ServiceLifetime.Scoped)
        {
            Check.NotNull(builder, nameof(builder));
            Check.NotNull(optionsAction, nameof(optionsAction));

            AddCoreServices(builder.Services, optionsAction, optionsLifetime);

            builder.Services.AddDbContext <EventStoreContext>();
            builder.Services.AddTransient <IEventStore, EventStoreManager>();

            return(builder);
        }
        public static LinFxBuilder AddDatabase(this LinFxBuilder builder, Action <DbConnectionOptions> optionsAction)
        {
            Check.NotNull(builder, nameof(builder));

            //var factory = new DbConnectionFactory(connectionString, PostgreSqlProvider.Instance);
            //var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new PostgreSqlDialect());
            //var db = new Database(factory.Create(), new SqlGeneratorImpl(config));

            //var factory = new DbConnectionFactory(connectionString, MySqlProvider.Instance);
            //var config = new DapperExtensionsConfiguration(typeof(AutoClassMapper<>), new List<Assembly>(), new MySqlDialect());
            //return new Database(factory.Create(), new SqlGeneratorImpl(config));

            builder.Services.AddTransient <IDatabase, Database>();

            return(builder);
        }
Exemplo n.º 21
0
        public static LinFxBuilder AddDapperExtensions(this LinFxBuilder builder, Action setupAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            //builder.Services.Configure(setupAction);
            //builder.Services.Add(ServiceDescriptor.Singleton<IDistributedCache, RedisCache>());

            return(builder);
        }
        /// <summary>
        /// Adds authorization services to the specified <see cref="LinFxBuilder" />.
        /// </summary>
        /// <param name="builder">The current <see cref="LinFxBuilder" /> instance. </param>
        /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
        public static LinFxBuilder AddAuthorization(this LinFxBuilder builder)
        {
            builder.Services.OnRegistred(AuthorizationInterceptorRegistrar.RegisterIfNeeded);
            AutoAddDefinitionProviders(builder.Services);

            builder.Services
            .AddAuthorizationCore()
            .AddSingleton <IAuthorizationHandler, PermissionRequirementHandler>();

            builder.Services.Configure <PermissionOptions>(options =>
            {
                options.ValueProviders.Add <UserPermissionValueProvider>();
                options.ValueProviders.Add <RolePermissionValueProvider>();
                options.ValueProviders.Add <ClientPermissionValueProvider>();
            });

            return(builder);
        }
Exemplo n.º 23
0
        public static LinFxBuilder AddRabbitMqPersistentConnection(this LinFxBuilder builder, Action <RabbitMqOptions> optionsAction)
        {
            var options = new RabbitMqOptions();

            optionsAction?.Invoke(options);

            builder.Services.AddSingleton((Func <IServiceProvider, IRabbitMqPersistentConnection>)(sp =>
            {
                var logger  = sp.GetRequiredService <ILogger <DefaultRabbitMqPersistentConnection> >();
                var factory = new ConnectionFactory
                {
                    HostName = options.Host,
                    UserName = options.UserName,
                    Password = options.Password,
                };
                return(new DefaultRabbitMqPersistentConnection(factory, logger));
            }));

            return(builder);
        }
 public static LinFxBuilder AddHttpContextPrincipalAccessor(this LinFxBuilder fx)
 {
     fx.Services.AddHttpContextAccessor();
     fx.Services.AddTransient <IHttpContextPrincipalAccessor, HttpContextPrincipalAccessor>();
     return(fx);
 }
 public static LinFxBuilder AddHttpContextPrincipalAccessor(this LinFxBuilder builder)
 {
     builder.Services.AddHttpContextAccessor();
     builder.Services.AddTransient <IHttpContextPrincipalAccessor, HttpContextPrincipalAccessor>();
     return(builder);
 }
Exemplo n.º 26
0
 public static LinFxBuilder AddEmail(this LinFxBuilder fx, Action <EmailSenderOptions> optionsAction)
 {
     fx.Services.Configure(optionsAction);
     fx.Services.AddSingleton <IEmailSender, SmtpEmailSender>();
     return(fx);
 }
        /// <summary>
        /// Adds Redis distributed caching services to the specified <see cref="LinFxBuilder" />.
        /// </summary>
        /// <param name="builder">The <see cref="LinFxBuilder" /> to add services to.</param>
        /// <param name="setupAction">An <see cref="Action{RedisCacheOptions}"/> to configure the provided
        /// <see cref="RedisCacheOptions"/>.</param>
        /// <returns>The <see cref="LinFxBuilder"/> so that additional calls can be chained.</returns>
        public static LinFxBuilder AddDistributedRedisCache(this LinFxBuilder builder, Action <RedisCacheOptions> setupAction)
        {
            builder.Services.AddDistributedRedisCache(setupAction);

            return(builder);
        }