@@ -13,6 +13,7 @@ namespace Ecommerce.Infrastructure;
1313using Ecommerce . Application . Common . Interfaces . Providers . Forex ;
1414using Ecommerce . Application . Common . Interfaces . Providers . Localization ;
1515using Ecommerce . Application . Common . Interfaces . Providers . Payment . Stripe ;
16+ using Ecommerce . Application . Common . Interfaces . Providers . Search . Elastic ;
1617using Ecommerce . Application . Common . Interfaces . Storage ;
1718using Ecommerce . Application . Common . Utilities ;
1819using Ecommerce . Application . Services . Storage ;
@@ -30,8 +31,10 @@ namespace Ecommerce.Infrastructure;
3031using Ecommerce . Infrastructure . Services . Providers . Forex ;
3132using Ecommerce . Infrastructure . Services . Providers . Payment ;
3233using Ecommerce . Infrastructure . Services . Providers . Payment . Stripe ;
34+ using Ecommerce . Infrastructure . Services . Providers . Search . Elastic ;
3335using Ecommerce . Infrastructure . Services . Providers . Smtp ;
3436using Ecommerce . Infrastructure . Services . Storage ;
37+ using Elastic . Clients . Elasticsearch ;
3538using IdentityModel ;
3639using Microsoft . AspNetCore . Authentication ;
3740using Microsoft . AspNetCore . Authentication . Cookies ;
@@ -80,6 +83,8 @@ IConfigurationManager configuration
8083 // stripe, paypal .. etc
8184 services . AddPaymentGateways ( ) ;
8285
86+ services . AddElastic ( configuration ) ;
87+
8388 return services ;
8489 }
8590
@@ -249,6 +254,8 @@ public static IServiceCollection AddAppSettings(
249254 IConfigurationManager configuration
250255 )
251256 {
257+ services . Configure < ElasticSettings > ( configuration . GetSection ( ElasticSettings . SectionName ) ) ;
258+
252259 services . Configure < DatabaseOptions > ( configuration . GetSection ( DatabaseOptions . SectionName ) ) ;
253260
254261 services . Configure < PaymentOptions > ( configuration . GetSection ( PaymentOptions . SectionName ) ) ;
@@ -300,7 +307,7 @@ IConfigurationManager configuration
300307 {
301308 services . AddScoped < ISmtpClientWrapper > ( sp =>
302309 {
303- string ? host = configuration . GetConnectionString ( $ "{ EmailSettings . SectionName } :Host") ;
310+ string ? host = configuration [ $ "{ EmailSettings . SectionName } :Host"] ;
304311
305312 if ( host is null )
306313 {
@@ -317,4 +324,23 @@ public static IServiceCollection AddPaymentGateways(this IServiceCollection serv
317324 services . AddTransient < IStripeService , StripeService > ( ) ;
318325 return services ;
319326 }
327+
328+ public static IServiceCollection AddElastic (
329+ this IServiceCollection services ,
330+ IConfigurationManager configuration
331+ )
332+ {
333+ var elasticUri = configuration [ $ "{ ElasticSettings . SectionName } :ConnectionString"] ;
334+ if ( elasticUri == null )
335+ {
336+ throw new Exception ( "Elastic Connection String is null." ) ;
337+ }
338+
339+ var elasticClient = new ElasticsearchClient ( new Uri ( elasticUri ) ) ;
340+
341+ services . AddSingleton ( elasticClient ) ;
342+ services . AddScoped ( typeof ( IElasticSearch < > ) , typeof ( ElasticSearch < > ) ) ;
343+
344+ return services ;
345+ }
320346}
0 commit comments