diff --git a/samples/BookStore/Acme.BookStore.sln b/samples/BookStore/Acme.BookStore.sln index 49f9115781..b0a02d2dde 100644 --- a/samples/BookStore/Acme.BookStore.sln +++ b/samples/BookStore/Acme.BookStore.sln @@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Application. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Acme.BookStore.Web.Tests", "test\Acme.BookStore.Web.Tests\Acme.BookStore.Web.Tests.csproj", "{5F1B28C6-8D0C-4155-92D0-252F7EA5F674}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Acme.BookStore.ConsoleApiClient", "test\Acme.BookStore.ConsoleApiClient\Acme.BookStore.ConsoleApiClient.csproj", "{3DED9AA7-1FC4-435D-9934-BCD37B43F744}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {5F1B28C6-8D0C-4155-92D0-252F7EA5F674}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F1B28C6-8D0C-4155-92D0-252F7EA5F674}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F1B28C6-8D0C-4155-92D0-252F7EA5F674}.Release|Any CPU.Build.0 = Release|Any CPU + {3DED9AA7-1FC4-435D-9934-BCD37B43F744}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DED9AA7-1FC4-435D-9934-BCD37B43F744}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DED9AA7-1FC4-435D-9934-BCD37B43F744}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DED9AA7-1FC4-435D-9934-BCD37B43F744}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -60,6 +66,7 @@ Global {068855E8-9240-4F1A-910B-CF825794513B} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} {50B2631D-129C-47B3-A587-029CCD6099BC} = {04DBDB01-70F4-4E06-B468-8F87850B22BE} {5F1B28C6-8D0C-4155-92D0-252F7EA5F674} = {04DBDB01-70F4-4E06-B468-8F87850B22BE} + {3DED9AA7-1FC4-435D-9934-BCD37B43F744} = {04DBDB01-70F4-4E06-B468-8F87850B22BE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} diff --git a/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj new file mode 100644 index 0000000000..0582d6f067 --- /dev/null +++ b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Acme.BookStore.ConsoleApiClient.csproj @@ -0,0 +1,14 @@ + + + + Exe + netcoreapp2.1 + + + + + + + + + diff --git a/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/ApiClientDemoService.cs b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/ApiClientDemoService.cs new file mode 100644 index 0000000000..d16746bdb8 --- /dev/null +++ b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/ApiClientDemoService.cs @@ -0,0 +1,26 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.DependencyInjection; + +namespace Acme.BookStore.ConsoleApiClient +{ + public class ApiClientDemoService : ITransientDependency + { + private readonly IBookAppService _bookAppService; + + public ApiClientDemoService(IBookAppService bookAppService) + { + _bookAppService = bookAppService; + } + + public async Task RunAsync() + { + var output = await _bookAppService.GetListAsync(new PagedAndSortedResultRequestDto()); + foreach (var bookDto in output.Items) + { + Console.WriteLine($"[BOOK {bookDto.Id}] Name={bookDto.Name}, Price={bookDto.Price}"); + } + } + } +} diff --git a/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/ConsoleApiClientModule.cs b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/ConsoleApiClientModule.cs new file mode 100644 index 0000000000..8bd13aee76 --- /dev/null +++ b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/ConsoleApiClientModule.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Autofac; +using Volo.Abp.Http.Client; +using Volo.Abp.Modularity; + +namespace Acme.BookStore.ConsoleApiClient +{ + [DependsOn( + typeof(AbpAutofacModule), + typeof(AbpHttpClientModule), + typeof(BookStoreApplicationModule) + )] + public class ConsoleApiClientModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.Configure(options => + { + options.RemoteServices.Default = new RemoteServiceConfiguration("http://localhost:53929/"); + }); + + context.Services.AddHttpClientProxies( + typeof(BookStoreApplicationModule).Assembly + ); + } + } +} diff --git a/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Program.cs b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Program.cs new file mode 100644 index 0000000000..3be13e1281 --- /dev/null +++ b/samples/BookStore/test/Acme.BookStore.ConsoleApiClient/Program.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Threading; + +namespace Acme.BookStore.ConsoleApiClient +{ + class Program + { + static void Main(string[] args) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + })) + { + application.Initialize(); + + using (var scope = application.ServiceProvider.CreateScope()) + { + var demoService = scope.ServiceProvider.GetRequiredService(); + AsyncHelper.RunSync(() => demoService.RunAsync()); + } + + Console.WriteLine("Press ENTER to stop application..."); + Console.ReadLine(); + } + } + } +}