Skip to content

Core Platform

Huy Nguyen edited this page Apr 5, 2025 · 2 revisions

Core Platform

The Core Platform is the foundation of Mixcore CMS, providing essential services and infrastructure for all applications. This document details the core components and their functionality.

Core Services

1. Authentication Service

The Authentication Service handles user authentication and session management:

public interface IAuthenticationService
{
    Task<AuthenticationResult> AuthenticateAsync(string username, string password);
    Task<AuthenticationResult> RefreshTokenAsync(string refreshToken);
    Task<bool> ValidateTokenAsync(string token);
}

Configuration

{
  "Authentication": {
    "Jwt": {
      "Issuer": "mixcore",
      "Audience": "mixcore-clients",
      "SecretKey": "your-secret-key",
      "ExpiryInMinutes": 60
    }
  }
}

2. Authorization Service

The Authorization Service manages access control and permissions:

public interface IAuthorizationService
{
    Task<bool> HasPermissionAsync(string userId, string permission);
    Task<IEnumerable<string>> GetUserRolesAsync(string userId);
    Task<bool> IsInRoleAsync(string userId, string role);
}

Permission Structure

module:action:resource
example: content:edit:page

3. Data Access Service

The Data Access Service provides a unified interface for database operations:

public interface IRepository<T> where T : class
{
    Task<T> GetByIdAsync(int id);
    Task<IEnumerable<T>> GetAllAsync();
    Task<T> AddAsync(T entity);
    Task UpdateAsync(T entity);
    Task DeleteAsync(T entity);
}

Configuration

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=mixcore;Trusted_Connection=True;"
  },
  "DataAccess": {
    "UseCache": true,
    "CacheDuration": 300,
    "BatchSize": 100
  }
}

Module System

1. Module Discovery

The Module System automatically discovers and loads modules:

public interface IModule
{
    string Name { get; }
    string Version { get; }
    void ConfigureServices(IServiceCollection services);
    void Configure(IApplicationBuilder app);
}

Module Registration

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMixcoreModules();
    }
}

2. Module Dependencies

Modules can declare dependencies on other modules:

[ModuleDependency(typeof(OtherModule))]
public class MyModule : IModule
{
    // Module implementation
}

Service Container

1. Dependency Injection

The Service Container manages service registration and resolution:

public interface IServiceContainer
{
    void Register<TService, TImplementation>(ServiceLifetime lifetime);
    TService Resolve<TService>();
    object Resolve(Type serviceType);
}

Service Registration

public class Module : IModule
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddScoped<IMyService, MyService>();
        services.AddTransient<IMyOtherService, MyOtherService>();
        services.AddSingleton<IMySingletonService, MySingletonService>();
    }
}

Configuration Management

1. Configuration Provider

The Configuration Provider manages application settings:

public interface IConfigurationProvider
{
    T GetValue<T>(string key);
    T GetSection<T>(string section);
    void Reload();
}

Configuration Sources

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
    }
}

Event System

1. Event Bus

The Event Bus facilitates event-driven architecture:

public interface IEventBus
{
    void Subscribe<TEvent>(IEventHandler<TEvent> handler);
    void Publish<TEvent>(TEvent @event);
    void Unsubscribe<TEvent>(IEventHandler<TEvent> handler);
}

Event Handling

public class MyEventHandler : IEventHandler<MyEvent>
{
    public Task HandleAsync(MyEvent @event)
    {
        // Handle the event
        return Task.CompletedTask;
    }
}

Logging System

1. Logger

The Logger provides centralized logging:

public interface ILogger
{
    void Log(LogLevel level, string message, Exception exception = null);
    void LogInformation(string message);
    void LogWarning(string message);
    void LogError(string message, Exception exception = null);
}

Logging Configuration

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "System": "Warning"
    },
    "File": {
      "Path": "logs/mixcore-{Date}.log",
      "RetentionDays": 7
    }
  }
}

Next Steps

Need Help?

Clone this wiki locally