If you're creating a bug/problem report, please include the followings:
- ABP Framework version: v6.0.2
- UI type: MVC
- DB provider: EF Core
Hi,
I want my AppServices to return Fake or Real data based on how clients call. Client can either ask for Real or Test data. so what is the best way to implement it because I have multiple AppServices and each has multiple actions.
Should I create 2 AppServices: RealAppService & FakeAppService
plus, what is the best way for client to ask for real or fake data. should client pass parameter in request header and if they do in the request header. how can I intercept the request and based on header value instantiate the real or fake app service.
3 Answer(s)
-
0
hi
You can add a parameter on the request header. and inject the
IHttpContextAccessor
to try to get this parameter.I think one AppService is enough.
-
0
this mean I need to inject IHttpContextAccessor in each AppService and read header value in each app service methods to make decision for fake or real data.
just wondering, is there any other approach ?
-
0
hi
You add consider adding a factory method to resolve the
IYourAppService
.Fake code:
context.Services.AddTransient<IIdentityUserAppService>(serviceProvider => { if (serviceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext?.Request.IsHttps) { serviceProvider.GetRequiredService<IdentityUserAppService>(); } return serviceProvider.GetRequiredService<MyIdentityUserAppService>();; });