Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
EShop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
EShop
Commits
978f1fd1
Commit
978f1fd1
authored
May 09, 2020
by
gdlcf88
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redesigned PaymentServiceResolver
parent
9da44f87
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
23 deletions
+19
-23
PaymentAppService.cs
...tion/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs
+1
-1
EShopPaymentsDomainModule.cs
...omain/EasyAbp/EShop/Payments/EShopPaymentsDomainModule.cs
+5
-7
FreePaymentServiceProvider.cs
...Abp/EShop/Payments/Payments/FreePaymentServiceProvider.cs
+1
-3
IPaymentServiceResolver.cs
...asyAbp/EShop/Payments/Payments/IPaymentServiceResolver.cs
+3
-3
PaymentServiceResolver.cs
...EasyAbp/EShop/Payments/Payments/PaymentServiceResolver.cs
+8
-8
EasyMallDomainModule.cs
...l/aspnet-core/src/EasyMall.Domain/EasyMallDomainModule.cs
+1
-1
No files found.
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs
View file @
978f1fd1
...
...
@@ -32,7 +32,7 @@ namespace EasyAbp.EShop.Payments.Payments
{
await
CheckCreatePolicyAsync
();
var
providerType
=
await
_paymentServiceResolver
.
GetProviderTypeOrDefaultAsync
(
input
.
PaymentMethod
)
??
var
providerType
=
_paymentServiceResolver
.
GetProviderTypeOrDefault
(
input
.
PaymentMethod
)
??
throw
new
UnknownPaymentMethodException
(
input
.
PaymentMethod
);
var
provider
=
ServiceProvider
.
GetService
(
providerType
)
as
IPaymentServiceProvider
??
...
...
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/EShopPaymentsDomainModule.cs
View file @
978f1fd1
...
...
@@ -16,16 +16,14 @@ namespace EasyAbp.EShop.Payments
)]
public
class
EShopPaymentsDomainModule
:
AbpModule
{
public
override
void
PostConfigureServices
(
ServiceConfigurationContext
context
)
{
context
.
Services
.
TryAddTransient
<
IPaymentServiceProvider
,
FreePaymentServiceProvider
>();
}
public
override
void
OnApplicationInitialization
(
ApplicationInitializationContext
context
)
public
override
void
OnPostApplicationInitialization
(
ApplicationInitializationContext
context
)
{
var
resolver
=
context
.
ServiceProvider
.
GetService
<
IPaymentServiceResolver
>();
resolver
.
TryRegisterProviderAsync
(
FreePaymentServiceProvider
.
PaymentMethod
,
typeof
(
FreePaymentServiceProvider
));
if
(
resolver
.
GetPaymentMethods
().
Count
==
0
)
{
resolver
.
TryRegisterProvider
(
FreePaymentServiceProvider
.
PaymentMethod
,
typeof
(
FreePaymentServiceProvider
));
}
}
public
override
void
ConfigureServices
(
ServiceConfigurationContext
context
)
...
...
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/FreePaymentServiceProvider.cs
View file @
978f1fd1
...
...
@@ -7,9 +7,7 @@ using Volo.Abp.Timing;
namespace
EasyAbp.EShop.Payments.Payments
{
// [ExposeServices(typeof(IPaymentRepository))]
// [Dependency(ServiceLifetime.Transient, TryRegister = true)]
public
class
FreePaymentServiceProvider
:
IPaymentServiceProvider
public
class
FreePaymentServiceProvider
:
IPaymentServiceProvider
,
ITransientDependency
{
private
readonly
IClock
_clock
;
private
readonly
IPaymentRepository
_paymentRepository
;
...
...
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/IPaymentServiceResolver.cs
View file @
978f1fd1
...
...
@@ -6,10 +6,10 @@ namespace EasyAbp.EShop.Payments.Payments
{
public
interface
IPaymentServiceResolver
{
Task
<
bool
>
TryRegisterProviderAsync
(
string
paymentMethod
,
Type
providerType
);
bool
TryRegisterProvider
(
string
paymentMethod
,
Type
providerType
);
Task
<
List
<
string
>>
GetPaymentMethodsAsync
();
List
<
string
>
GetPaymentMethods
();
T
ask
<
Type
>
GetProviderTypeOrDefaultAsync
(
string
paymentMethod
);
T
ype
GetProviderTypeOrDefault
(
string
paymentMethod
);
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentServiceResolver.cs
View file @
978f1fd1
...
...
@@ -18,34 +18,34 @@ namespace EasyAbp.EShop.Payments.Payments
_serviceProvider
=
serviceProvider
;
}
public
virtual
Task
<
bool
>
TryRegisterProviderAsync
(
string
paymentMethod
,
Type
providerType
)
public
virtual
bool
TryRegisterProvider
(
string
paymentMethod
,
Type
providerType
)
{
if
(
Providers
.
ContainsKey
(
paymentMethod
))
{
return
Task
.
FromResult
(
false
)
;
return
false
;
}
using
(
var
scope
=
_serviceProvider
.
CreateScope
())
{
if
(
scope
.
ServiceProvider
.
GetService
(
providerType
)
==
null
)
{
return
Task
.
FromResult
(
false
)
;
return
false
;
}
}
Providers
.
Add
(
paymentMethod
,
providerType
);
return
Task
.
FromResult
(
true
)
;
return
true
;
}
public
virtual
Task
<
List
<
string
>>
GetPaymentMethodsAsync
()
public
virtual
List
<
string
>
GetPaymentMethods
()
{
return
Task
.
FromResult
(
Providers
.
Keys
.
ToList
()
);
return
Providers
.
Keys
.
ToList
(
);
}
public
virtual
T
ask
<
Type
>
GetProviderTypeOrDefaultAsync
(
string
paymentMethod
)
public
virtual
T
ype
GetProviderTypeOrDefault
(
string
paymentMethod
)
{
return
Task
.
FromResult
(
Providers
.
GetOrDefault
(
paymentMethod
)
);
return
Providers
.
GetOrDefault
(
paymentMethod
);
}
}
}
\ No newline at end of file
samples/EasyMall/aspnet-core/src/EasyMall.Domain/EasyMallDomainModule.cs
View file @
978f1fd1
...
...
@@ -60,7 +60,7 @@ namespace EasyMall
{
var
resolver
=
context
.
ServiceProvider
.
GetService
<
IPaymentServiceResolver
>();
resolver
.
TryRegisterProvider
Async
(
WeChatPayPaymentServiceProvider
.
PaymentMethod
,
typeof
(
WeChatPayPaymentServiceProvider
));
resolver
.
TryRegisterProvider
(
WeChatPayPaymentServiceProvider
.
PaymentMethod
,
typeof
(
WeChatPayPaymentServiceProvider
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment