Anto Subash.

This is second post of the series: .NET Microservice with ABP

Posts in the Series

Part 1. Initial Setup

Part 2. Shared Project (this post)

Part 3. Administration Service

Part 4. Identity Service

Part 5. SaaS Service

Part 6. DB Migration

Part 7. Yarp and Tye

Part 8. Identity server and Angular App

Part 9. Distributed event bus

Part 10. Docker and CI/CD

Part 11. Add a New service

Part 12. Central Logging

Table of contents

Setup Shared project

We need the shared project so that we can share some start up code. This part is not necessary but it is good to have and shared module which will we can reuse.

Install nuget

The setup script in the part 1 of this series has created a empty class library project called Tasky.Shared.Hosting. we will add the following nuget packages to that project. These nuget packages are essential for all the microservice we are going to create. So we will install these in a shared project and add this shared project as a reference in all the services. This will we can save some time.

1<PackageReference Include="Volo.Abp.Autofac" Version="5.1.4"/>
2<PackageReference Include="Volo.Abp.EventBus.RabbitMQ" Version="5.1.4"/>
3<PackageReference Include="Volo.Abp.Localization" Version="5.1.4"/>
4<PackageReference Include="Volo.Abp.MultiTenancy" Version="5.1.4"/>
5<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy" Version="5.1.4"/>
6<PackageReference Include="Serilog.AspNetCore" Version="4.1.0"/>
7<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0"/>
8<PackageReference Include="IdentityModel" Version="5.1.0"/>
9<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0"/>
10<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="6.0.0"/>
11<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="5.1.4"/>
12<PackageReference Include="Volo.Abp.Http.Client.IdentityModel.Web" Version="5.1.4"/>
13<PackageReference Include="Volo.Abp.Identity.HttpApi.Client" Version="5.1.4"/>
14<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="5.1.4"/>
15<PackageReference Include="Volo.Abp.Swashbuckle" Version="5.1.4"/>
16<PackageReference Include="Volo.Abp.EntityFrameworkCore" Version="5.1.4"/>
17<PackageReference Include="Volo.Abp.EntityFrameworkCore.PostgreSql" Version="5.1.4"/>

Shared module

Lets create a shared TaskyHostingModule which can be added as dependency for all of our services.

1using Volo.Abp.AspNetCore.MultiTenancy;
2using Volo.Abp.AspNetCore.Serilog;
3using Volo.Abp.Autofac;
4using Volo.Abp.Caching.StackExchangeRedis;
5using Volo.Abp.Data;
6using Volo.Abp.EntityFrameworkCore;
7using Volo.Abp.EntityFrameworkCore.PostgreSql;
8using Volo.Abp.EventBus.RabbitMq;
9using Volo.Abp.Localization;
10using Volo.Abp.Modularity;
11using Volo.Abp.MultiTenancy;
12using Volo.Abp.Swashbuckle;
13
14namespace Tasky.Shared.Hosting;
15
16[DependsOn(
17    typeof(AbpAutofacModule),
18    typeof(AbpDataModule),
19    typeof(AbpCachingStackExchangeRedisModule),
20    typeof(AbpAspNetCoreSerilogModule),
21    typeof(AbpAspNetCoreMultiTenancyModule),
22    typeof(AbpSwashbuckleModule),
23    typeof(AbpEventBusRabbitMqModule),
24    typeof(AbpEntityFrameworkCoreModule),
25    typeof(AbpEntityFrameworkCorePostgreSqlModule)
26)]
27public class TaskyHostingModule : AbpModule
28{
29    public override void ConfigureServices(ServiceConfigurationContext context)
30    {
31        Configure<AbpDbContextOptions>(options =>
32        {
33            options.UseNpgsql();
34        });
35
36        Configure<AbpMultiTenancyOptions>(options =>
37        {
38            options.IsEnabled = true;
39        });
40
41        Configure<AbpDbConnectionOptions>(options =>
42        {
43            options.Databases.Configure("SaaSService", database =>
44            {
45                database.MappedConnections.Add("AbpTenantManagement");
46                database.IsUsedByTenants = false;
47            });
48
49            options.Databases.Configure("AdministrationService", database =>
50            {
51                database.MappedConnections.Add("AbpAuditLogging");
52                database.MappedConnections.Add("AbpPermissionManagement");
53                database.MappedConnections.Add("AbpSettingManagement");
54                database.MappedConnections.Add("AbpFeatureManagement");
55            });
56
57            options.Databases.Configure("IdentityService", database =>
58            {
59                database.MappedConnections.Add("AbpIdentity");
60                database.MappedConnections.Add("AbpIdentityServer");
61            });
62        });
63
64        Configure<AbpLocalizationOptions>(options =>
65        {
66            options.Languages.Add(new LanguageInfo("ar", "ar", "العربية"));
67            options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
68            options.Languages.Add(new LanguageInfo("en", "en", "English"));
69            options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)"));
70            options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish"));
71            options.Languages.Add(new LanguageInfo("fr", "fr", "Français"));
72            options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi", "in"));
73            options.Languages.Add(new LanguageInfo("is", "is", "Icelandic", "is"));
74            options.Languages.Add(new LanguageInfo("it", "it", "Italiano", "it"));
75            options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar"));
76            options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
77            options.Languages.Add(new LanguageInfo("ro-RO", "ro-RO", "Română"));
78            options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
79            options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak"));
80            options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
81            options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
82            options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
83            options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsch"));
84            options.Languages.Add(new LanguageInfo("es", "es", "Español"));
85        });
86    }
87}

This is the first setup of our microservice application. the package and the modules in this project will become the base of all the services.

Repo: https://github.com/antosubash/AbpMicroservice

Buy Me a Coffee at ko-fi.com