1+ using System ;
12using System . Collections . Generic ;
23using System . Linq ;
34using System . Threading ;
1516using VirtoCommerce . Xapi . Core . Infrastructure ;
1617using VirtoCommerce . Xapi . Core . Models ;
1718using VirtoCommerce . Xapi . Core . Queries ;
19+ using VirtoCommerce . Xapi . Core . Services ;
1820using VirtoCommerce . Xapi . Core . Subscriptions ;
1921using StoreSettingGeneral = VirtoCommerce . StoreModule . Core . ModuleConstants . Settings . General ;
2022using StoreSettingSeo = VirtoCommerce . StoreModule . Core . ModuleConstants . Settings . SEO ;
@@ -31,6 +33,7 @@ public class GetStoreQueryHandler : IQueryHandler<GetStoreQuery, StoreResponse>
3133 private readonly GraphQLWebSocketOptions _webSocketOptions ;
3234 private readonly StoresOptions _storeOptions ;
3335 private readonly IStoreAuthenticationService _storeAuthenticationService ;
36+ private readonly IStoreDomainResolverService _storeDomainResolverService ;
3437
3538 public GetStoreQueryHandler (
3639 IStoreService storeService ,
@@ -40,8 +43,8 @@ public GetStoreQueryHandler(
4043 IOptions < IdentityOptions > identityOptions ,
4144 IOptions < GraphQLWebSocketOptions > webSocketOptions ,
4245 IOptions < StoresOptions > storeOptions ,
43- IStoreAuthenticationService storeAuthenticationService )
44-
46+ IStoreAuthenticationService storeAuthenticationService ,
47+ IStoreDomainResolverService storeDomainResolverService )
4548 {
4649 _storeService = storeService ;
4750 _storeSearchService = storeSearchService ;
@@ -51,25 +54,13 @@ public GetStoreQueryHandler(
5154 _identityOptions = identityOptions . Value ;
5255 _webSocketOptions = webSocketOptions . Value ;
5356 _storeOptions = storeOptions . Value ;
57+ _storeDomainResolverService = storeDomainResolverService ;
5458 }
5559
5660 public async Task < StoreResponse > Handle ( GetStoreQuery request , CancellationToken cancellationToken )
5761 {
58- Store store = null ;
59-
60- if ( ! string . IsNullOrEmpty ( request . StoreId ) )
61- {
62- store = await _storeService . GetByIdAsync ( request . StoreId , clone : false ) ;
63- }
64- else if ( ! string . IsNullOrEmpty ( request . Domain ) )
65- {
66- store = await ResolveStoreByDomain ( request . Domain ) ;
67-
68- if ( store == null && ! string . IsNullOrEmpty ( _storeOptions . DefaultStore ) )
69- {
70- store = await _storeService . GetByIdAsync ( _storeOptions . DefaultStore , clone : false ) ;
71- }
72- }
62+ var storeResolverRequest = CreateStoreResolveRequest ( request ) ;
63+ var store = await _storeDomainResolverService . GetStoreAsync ( storeResolverRequest ) ;
7364
7465 if ( store == null )
7566 {
@@ -135,6 +126,15 @@ public async Task<StoreResponse> Handle(GetStoreQuery request, CancellationToken
135126 return response ;
136127 }
137128
129+ protected virtual StoreDomainRequest CreateStoreResolveRequest ( GetStoreQuery request )
130+ {
131+ var storeResolverRequest = AbstractTypeFactory < StoreDomainRequest > . TryCreateInstance ( ) ;
132+ storeResolverRequest . StoreId = request . StoreId ;
133+ storeResolverRequest . Domain = request . Domain ;
134+ return storeResolverRequest ;
135+ }
136+
137+ [ Obsolete ( "Not being called anymore. Use IStoreDomainResolverService.ResolveStoreByDomain(string domain) method." , DiagnosticId = "VC0010" , UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/" ) ]
138138 protected virtual async Task < Store > ResolveStoreByDomain ( string domain )
139139 {
140140 if ( _storeOptions . Domains . TryGetValue ( domain , out var storeId ) )
0 commit comments