File tree Expand file tree Collapse file tree 5 files changed +84
-31
lines changed
src/aspdotnet-client-directkit-json2 Expand file tree Collapse file tree 5 files changed +84
-31
lines changed Original file line number Diff line number Diff line change 33using System . Linq ;
44using System . Threading . Tasks ;
55using Microsoft . AspNetCore . Mvc ;
6+ using Microsoft . AspNetCore . Http . Features ;
7+ using com . lemonway ;
8+ using Microsoft . Extensions . Options ;
9+ using aspdotnet_client_directkit_json2 . Services ;
610
711namespace aspdotnet_client_directkit_json2 . Controllers
812{
913 public class HomeController : Controller
1014 {
11- public IActionResult Index ( )
12- {
13- return View ( ) ;
14- }
15-
16- public IActionResult About ( )
17- {
18- ViewData [ "Message" ] = "Your application description page." ;
19-
20- return View ( ) ;
21- }
22-
23- public IActionResult Contact ( )
24- {
25- ViewData [ "Message" ] = "Your contact page." ;
15+ private readonly ILwService lwService ;
16+ private readonly LwConfig lwConfig ;
17+
2618
27- return View ( ) ;
28- }
19+ public HomeController ( ILwService lwService , IOptions < LwConfig > lwConfigAccessor )
20+ {
21+ this . lwService = lwService ;
22+ this . lwConfig = lwConfigAccessor . Value ;
23+ }
2924
30- public IActionResult Error ( )
25+ public JsonResult Index ( )
3126 {
32- return View ( ) ;
33- }
27+ var request = new LwRequest ( lwConfig , new EndUserInfoProvider ( Request ) ) ;
28+ var response = lwService . Call ( "GetWalletDetails" , request . Set ( "wallet" , "sc" ) ) ;
29+ return new JsonResult ( response ) ;
30+ }
3431 }
3532}
Original file line number Diff line number Diff line change 1+ using com . lemonway ;
2+ using Microsoft . AspNetCore . Http ;
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
6+ using System . Threading . Tasks ;
7+
8+ namespace aspdotnet_client_directkit_json2 . Services
9+ {
10+ /// <summary>
11+ /// Get user info from the http request
12+ /// </summary>
13+ public class EndUserInfoProvider : IEndUserInfoProvider
14+ {
15+ private readonly HttpRequest httpRequest ;
16+ public EndUserInfoProvider ( HttpRequest httpRequest )
17+ {
18+ this . httpRequest = httpRequest ;
19+ }
20+
21+ public EndUserInfo GetEndUserInfo ( )
22+ {
23+ return new EndUserInfo
24+ {
25+ IP = httpRequest . HttpContext . Connection . RemoteIpAddress . ToString ( ) ,
26+ UserAgent = httpRequest . Headers [ "User-Agent" ] . ToString ( )
27+ } ;
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change 77using Microsoft . Extensions . Configuration ;
88using Microsoft . Extensions . DependencyInjection ;
99using Microsoft . Extensions . Logging ;
10+ using com . lemonway ;
11+ using Microsoft . AspNetCore . Http ;
12+ using Microsoft . AspNetCore . Http . Features ;
1013
1114namespace aspdotnet_client_directkit_json2
1215{
1316 public class Startup
1417 {
15- public Startup ( IHostingEnvironment env )
18+
19+ public Startup ( IHostingEnvironment env )
1620 {
1721 var builder = new ConfigurationBuilder ( )
1822 . SetBasePath ( env . ContentRootPath )
@@ -27,8 +31,20 @@ public Startup(IHostingEnvironment env)
2731 // This method gets called by the runtime. Use this method to add services to the container.
2832 public void ConfigureServices ( IServiceCollection services )
2933 {
30- // Add framework services.
31- services . AddMvc ( ) ;
34+ var lwConfigSection = Configuration . GetSection ( "LemonWay" ) ;
35+
36+ // Add framework services
37+ services . AddMvc ( ) ;
38+
39+ // inject the lemonway service configuration
40+ services . AddOptions ( ) ;
41+ services . Configure < LwConfig > ( lwConfigSection ) ;
42+
43+ // inject the lemonway service as singleton
44+ services . AddSingleton < ILwService , LwService > ( serviceProvider => {
45+ var directkitUrl = lwConfigSection . GetValue < string > ( "DirectkitJson2Url" ) ;
46+ return new LwService ( directkitUrl ) ;
47+ } ) ;
3248 }
3349
3450 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Original file line number Diff line number Diff line change 11{
2- "Logging" : {
3- "IncludeScopes" : false ,
4- "LogLevel" : {
5- "Default" : " Debug" ,
6- "System" : " Information" ,
7- "Microsoft" : " Information"
2+ "Logging" : {
3+ "IncludeScopes" : false ,
4+ "LogLevel" : {
5+ "Default" : " Debug" ,
6+ "System" : " Information" ,
7+ "Microsoft" : " Information"
8+ }
9+ },
10+
11+ "LemonWay" : {
12+ "DirectkitJson2Url" : " https://sandbox-api.lemonway.fr/mb/hiep/dev/directkitjson2/Service.asmx" ,
13+ "Login" : " society" ,
14+ "Password" : " 123456" ,
15+ "Language" : " en" ,
16+ "Version" : " 4.0"
817 }
9- }
18+
1019}
Original file line number Diff line number Diff line change 2020 "Microsoft.Extensions.Logging.Console" : " 1.0.0" ,
2121 "Microsoft.Extensions.Logging.Debug" : " 1.0.0" ,
2222 "Microsoft.Extensions.Options.ConfigurationExtensions" : " 1.0.0" ,
23- "Microsoft.VisualStudio.Web.BrowserLink.Loader" : " 14.0.0"
23+ "Microsoft.VisualStudio.Web.BrowserLink.Loader" : " 14.0.0" ,
24+ "LemonWayService" : " 1.0.0-*"
2425 },
2526
2627 "tools" : {
You can’t perform that action at this time.
0 commit comments