Пример #1
0
        public static IServiceCollection AddElasticSearchClient(this IServiceCollection services, Configuration configuration)
        {
            var pool     = new StaticConnectionPool(configuration.NodesUri);
            var settings = new ConnectionSettings(pool);

            settings.DefaultIndex(configuration.DefaultIndex);
            _client = new ElasticClient(settings);
            EnsureIndex(_client, _client.ConnectionSettings.DefaultIndex);
            services.AddSingleton(_client);
            services.AddScoped <IIndexService, IndexService>();
            services.AddScoped <ITriggerService, TriggerService>();
            IHookFunction hookFunction = new HookFunction();

            services.AddSingleton(hookFunction);
            services.AddSingleton <IExecuteTrigger, ExecuteTrigger>();
            services.BuildServiceProvider().GetService <IExecuteTrigger>();

            _client.Mapping <Group, GroupDTO>(s => s.SetType("group")
                                              .SetKeyProperty(item => item.ID)
                                              .SetMethodDelete(DeleteGroupIndex)
                                              .SetMakeMethod(MakeMethod.Delete, MakeMethod.Insert)
                                              .SetQuery(QueryExpression.BuildQuery <Group>()
                                                        .Include(item => item.GroupRoles)
                                                        .ThenInclude(item => item.Role)
                                                        .Include(item => item.GroupUsers)
                                                        .ThenInclude(item => item.User)));
            return(services);
        }