A proper way Dapper custom mapping settings initialization in ASP.NET

I have three-layers architecture mini-program as my hometask of some paid private online courses. Recently I added ASP.NET Core as replacement for my console presentation-lavel. But I also have custom mapping in a class for Dapper-program in the Data-layer:

    namespace CarRental.Data.Managers
{
    public class DapperConfigurationManager
    {
        // METHODS

    public void ConfigureGuidToStringMapping()
    {
        SqlMapper.AddTypeHandler(new GuidToStringTypeHandler());

        SqlMapper.RemoveTypeMap(typeof(Guid));
    }

    public void SetCustomMappingForEntities()
    {
        CustomPropertyTypeMap carMap = new CustomPropertyTypeMap(typeof(Car), PropertyInformation);
        CustomPropertyTypeMap customerMap = new CustomPropertyTypeMap(typeof(CustomerTemp), PropertyInformation);
        CustomPropertyTypeMap dealMap = new CustomPropertyTypeMap(typeof(Deal), PropertyInformation);
        CustomPropertyTypeMap inspectionMap = new CustomPropertyTypeMap(typeof(Inspection), PropertyInformation);
        CustomPropertyTypeMap repairMap = new CustomPropertyTypeMap(typeof(Repair), PropertyInformation);
        CustomPropertyTypeMap mechanicMap = new CustomPropertyTypeMap(typeof(Mechanic), PropertyInformation);

        SqlMapper.SetTypeMap(typeof(Car), carMap);
        SqlMapper.SetTypeMap(typeof(CustomerTemp), customerMap);
        SqlMapper.SetTypeMap(typeof(Deal), dealMap);
        SqlMapper.SetTypeMap(typeof(Inspection), inspectionMap);
        SqlMapper.SetTypeMap(typeof(Repair), repairMap);
        SqlMapper.SetTypeMap(typeof(Mechanic), mechanicMap);
    }

    public static PropertyInfo PropertyInformation(Type type, string attribName)
    {
        // BECAUSE THE METHOD IS STRONGLY TYPED, I CANNOT MOVE IT IN FROM THE OUTSIDE.
        Dictionary<string, string> columnProperties = new Dictionary<string, string>
        {
            { "carCarId", "CarId" },
            { "carVinCode", "VinCode" },
            { "carNumberPlate", "NumberPlate" },
            { "carBrand", "Brand" },
            { "carModel", "Model" },
            { "carPrice", "Price" },
            { "carNumberOfSeats", "NumberOfSeats" },
            { "carNumberOfDoors", "NumberOfDoors" },
            { "carMileage", "Mileage" },
            { "carMaxFuelCapacity", "MaxFuelCapacity" },
            { "carCurrentFuel", "CurrentFuel" },
            { "carYear", "Year" },
            { "carIsFitForUse", "IsFitForUse" },
            { "carEngine", "Engine" },
            { "carTransmission", "Transmission" },
            { "carInterior", "Interior" },
            { "carWheels", "Wheels" },
            { "carLights", "Lights" },
            { "carSignal", "Signal" },
            { "carColor", "Color" },
            { "carStatusId", "Status" },
            { "userIdNumber", "IdNumber" },
            { "userFirstName", "FirstName" },
            { "userLastName", "LastName" },
            { "userDateOfBirth", "DateOfBirth" },
            { "userUserName", "UserName" },
            { "userPassword", "Password" },
            { "userPassportNumber", "PassportNumber" },
            { "userDrivingLicenseNumber", "DrivingLicenseNumber" },
            { "userBasicDiscount", "BasicDiscount" },
            { "userCategory", "Category" },
            { "dealId", "Id" },
            { "dealCarId", "CarId" },
            { "dealVinCode", "VinCode" },
            { "dealCustomerId", "CustomerId" },
            { "dealPrice", "Price" },
            { "dealDealType", "DealType" },
            { "dealName", "Name" },
            { "inspectionInspectionId", "InspectionId" },
            { "inspectionCarId", "CarId" },
            { "inspectionInspectorId", "InspectorId" },
            { "inspectionInspectionDate", "InspectionDate" },
            { "inspectionStatusId", "Result" },
            { "repairId", "Id" },
            { "repairDate", "Date" },
            { "repairCarId", "CarId" },
            { "repairMechanicId", "MechanicId" },
            { "repairIsSuccessfull", "IsSuccessfull" },
            { "repairTotalCost", "TotalCost" },
            { "repairTechnicalInfo", "TechnicalInfo" },
            { "mechanId", "Id" },
            { "mechanName", "Name" },
            { "mechanSurename", "Surename" },
            { "mechanYear", "Year" }
        };

        if (columnProperties.ContainsKey(attribName))
        {
            return type.GetProperty(columnProperties[attribName]);
        }

        return type.GetProperty(attribName);
    }
}

}

I have tried to implement it like that:

    namespace CarRental.WebApi
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // TO CONFIGURE ORM FOR Car-CLASS.

        var carServiceManager = new ServiceManager();

        carServiceManager.InitializeManagment();

        carServiceManager.SupplementData.DapperConfigs.ConfigureGuidToStringMapping();
        carServiceManager.SupplementData.DapperConfigs.SetCustomMappingForEntities();

        var builder = WebApplication.CreateBuilder(args);

        // Add services to the container.

        builder.Services.AddControllers();
        // Learn more about configuring Swagger/OpenAPI at aka.ms/aspnetcore/swashbuckle
        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen();
        builder.Services.AddTransient<ServiceManager>(x => new ServiceManager());

        var app = builder.Build();

        // Configure the HTTP request pipeline.
        if (app.Environment.IsDevelopment())
        {
            app.UseSwagger();
            app.UseSwaggerUI();
        }

        app.UseHttpsRedirection();

        app.UseAuthorization();


        app.MapControllers();

        app.Run();
    }
}

}

But the teacher said it is not ‘ok’, because the instance of ServiceManager created and it can live for long time and so on, and so on. But also she said nothing about how to implement it in the right way… :S I never worked as programmer, I have only ‘basic C# course’, so I have no any idea what is the ‘proper way’ to implement it into ASP.NET Core, and tomorrow is the deadline of the hometask!

— So what is the proper way to implement custom mapping into ASP.NET, because without this mapping I cannot obtain the data from my remote Database…

P. S. This default templates with ‘var’ everywhere is kind of confusing… Hard to understand what happening in the source code, because cannot see types.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật