2026-05-15 02:48:28 +03:30
2024-01-25 04:39:39 +03:30
2024-01-25 04:39:39 +03:30
2024-01-25 04:39:39 +03:30
2025-12-22 23:38:34 +03:30
2026-05-15 02:48:28 +03:30
2024-01-25 04:39:39 +03:30
2024-01-25 04:39:39 +03:30
2026-05-09 22:20:59 +03:30
2024-01-25 04:39:39 +03:30
2026-05-09 22:20:59 +03:30
2024-01-25 04:39:39 +03:30
2024-01-25 04:39:39 +03:30
2024-01-25 04:39:39 +03:30
2026-05-06 04:42:41 +03:30

xCommons

it is a Part of xDashboard on SaherElm IT Center which provides:

  • Common Configuration Models.
  • Common Usefull extra Extensions.
  • Data Validation Provider.
  • Provided features such as Enums, Models, Attributes, Filters, Authorization Policies, Middlewares and Helpers.
  • etc.

this module has no dependency and itself uses as a base dependency for all XProject modules/

for configure and use this Module refer to DI.XDIHelperExtension.cs file.

Implementing

after adding this package as a dependency to your project you can do following:

1. Register it on DI

public void ConfigureServices (IServiceCollection services) {
    ...
    //
    // Register Validation Provider and all XCommons Module Services ...
    services.AddXCommons ();
    ...
}

this will provide XValidationHelper service which accessible through DI.

2. Register Application Configuration on DI

since many of features in this Framework works by accessing the configuration of class application. you had to register it on DI.

configure you app in appSettings.json:

{
  ...
  "Version": "0.1",
  "Name": "SaherElm Sample App",
  "DefaultLanguage": "fa-IR",
  "XPoweredValue": "SaherElmITCenter",
  "WelcomeMessage": "Welcome to Application",
  "AllowedOrigins": [
    "http://localhost:4200",
    "https://localhost:4200"
  ],
  ...
},

then register your configuration on DI in Startup file:

public void ConfigureServices (IServiceCollection services) {
    ...
    //
    // Register App Configuration ...
    services.AddXAppConfiguration (Configuration);
    var appConfiguration = services.GetRegisteredService<XAppConfiguration> ();
    ...
}

3. Register Available Cross Origin Resource sharing (Cors)

for determining which addresses can access your application and enabling core mechanism you can simply do it by follow this structure ...

NOTE: notice that you have configured allowed origins in appSettings.json before on AppConfiguration section.

public void ConfigureServices (IServiceCollection services) {
    ...
    //
    // Register Allowed Origins ...
    services.AddXCors (appConfiguration.AllowedOrigins);
    ...
}

the you can enable cors handling like this:

public void Configure (IApplicationBuilder app, IWebHostEnvironment env) {
    ...
    //
    // Using Cors ...
    app.UseXCors ();
    ...
}

Note: remember AllowedOrigins can provided using appSettings.json file dynamically;

4. Enable Swagger

also you can add swagger documentation to your project:

public void ConfigureServices (IServiceCollection services) {
    ...
    //
    // Register Api Versioning ...
    services.AddApiVersioning (opt => {
        //
        // Set Default Api Version ...
        opt.DefaultApiVersion = new ApiVersion (1, 0);

        //
        // Set Routing to Default API Version, if Version unspecified ...
        opt.AssumeDefaultVersionWhenUnspecified = true;

        //
        // Report All Available Api Versions on Response ...
        opt.ReportApiVersions = true;
    });

    //
    // Register Swagger ...
    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    var xmlPath = Path.Combine (AppContext.BaseDirectory, xmlFile);
    services.AddXSwagger (Configuration, xmlFilePath : xmlPath);
    ...
}

the you can enable swagger middleware like this:

public void Configure (IApplicationBuilder app, IWebHostEnvironment env) {
    ...
    //
    // Use Swagger Middleware ...
    app.UseXSwagger ();
    ...
}

Maintainer

Hadi Khazaee asl

https://www.saherelm.ir

hadi_khazaee_asl@yahoo.com

S
Description
xDashboard Commons Module
Readme
82 KiB
Languages
C# 100%