ModularSystem.Core
1.40.0-prerelease.6
See the version list below for details.
dotnet add package ModularSystem.Core --version 1.40.0-prerelease.6
NuGet\Install-Package ModularSystem.Core -Version 1.40.0-prerelease.6
<PackageReference Include="ModularSystem.Core" Version="1.40.0-prerelease.6" />
paket add ModularSystem.Core --version 1.40.0-prerelease.6
#r "nuget: ModularSystem.Core, 1.40.0-prerelease.6"
// Install ModularSystem.Core as a Cake Addin #addin nuget:?package=ModularSystem.Core&version=1.40.0-prerelease.6&prerelease // Install ModularSystem.Core as a Cake Tool #tool nuget:?package=ModularSystem.Core&version=1.40.0-prerelease.6&prerelease
ModularSystem Core Module (Under Development)
Build a Solid Basic CRUD Within Minutes
This library streamlines the foundational tasks of setting up web servers. ModularSystem aims to automate repetitive aspects of web application development in a modular and simple manner.
Overview
ModularSystem provides a collection of useful classes for daily development tasks. The core philosophy is to maintain a stable API model to facilitate communication between different servers without requiring specific adaptation layers. This enables parsing and understanding the interface exposed by a server without data mapping, typing, or adaptation. The term 'Modular' reflects the system's extensibility, allowing developers to add modules to enhance functionality and promote code reuse.
CRUD Operations
The library offers complete CRUD (Create, Read, Update, Delete) operations, featuring a well-defined query mechanism based on Expression trees.
Generics
The crud service employs a generic type T
, which inherits from a base class. This design allows the library to apply dynamic CRUD operations to any class. Developers will need to implement or override specific methods, where application-specific logic like validation and presentation can be added.
Service Interface
The entity service interface serves as the foundation for CRUD operations. It consolidates validation logic, data access layers, and much more to expose methods through the entity.
Usage
Initializing the Library
For the library to function correctly, it's essential to initialize it before use. This step ensures that all modules and components are properly set up and ready for use.
Step-by-step Guide:
Import the necessary namespace: Add the ModularSystem.Core namespace to your application.
Call the Initializer: Use the Initializer.Run() method to initialize the library.
Example:
using ModularSystem.Core;
namespace MyApp;
public static class Program
{
public static void Main(string[] args)
{
Initializer.Run();
}
}
Getting Started
- To begin, create the data structure for the entity model. This model should implement the
IQueryableModel
interface. Extend fromQueryableModel
to automatically implement all required methods.
Example:
using ModularSystem.Core;
namespace MyApp;
public class User : QueryableModel
{
public string Email { get; set; }
public string Password { get; set; }
}
- Implement the IEntityService<T> interface. One approach is to extend from EntityService<T> and implement the abstract methods.
Example:
using ModularSystem.Core;
namespace MyApp;
public class UserService : EntityService<User>
{
// ...
}
- Now call the service anywhere to create a usecase.
Example:
namespace MyApp;
public class Program
{
public static async Task Main()
{
using var userService = new UserService();
var user = new User()
{
Email = "foo@bar.baz",
Password = "super-password"
};
var userId = await userService.CreateAsync(user);
}
}
Note that the raw service class requires implementation of certain methods and properties:
Example:
using ModularSystem.Core;
namespace MyApp;
public class UserService : EntityService<User>
{
protected override IDataAccessObject<User> DataAccessObject { get; }
public UserService()
{
//...
}
protected override MemberExpression CreateIdSelectorExpression (ParameterExpression parameter)
{
//...
}
protected override object? TryParseId(string id)
{
//...
}
}
The library also provides an Entity Framework implementation, with additional modules offering other implementations.
Example:
using ModularSystem.Core;
using ModularSystem.EntityFramework;
namespace MyApp;
public class UserService : EFEntityService<User>
{
protected override IDataAccessObject<User> DataAccessObject { get; }
public UserService()
{
//...
}
}
Data Access Object Interface (IDAO)
The IDataAccessObject interface houses the code for database access, serving as the entity's I/O interface for a given resource. The core library includes embedded implementations like EFCoreDataAccessObject.
Example:
using ModularSystem.Core;
using ModularSystem.EntityFramework;
namespace MyApp;
public class UserService : EFEntityService<User>
{
protected override IDataAccessObject<User> DataAccessObject { get; }
public UserService()
{
DataAccessObject = new EFCoreDataAccessObject<User>(new MyDbContext());
}
}
IValidator<T> Interface
Here you define data validation rules for specific data structures. Implement a validation method to return or throw exceptions if the data is in an invalid state.
Example:
using ModularSystem.Core;
using ModularSystem.EntityFramework;
namespace MyApp;
public class UserValidator : IValidator<User>
{
public Task<Exception?> ValidateAsync(User instance)
{
//...
}
}
public class UserService : EFEntityService<User>
{
protected override IDataAccessObject<User> DataAccessObject { get; }
public UserService()
{
DataAccessObject = new EFCoreDataAccessObject<User>(new MyDbContext());
Validator = new UserValidator();
}
}
Wiring it All Together
Entities can be utilized by other layers to create use cases, thus enabling clean and desired code behavior.
Example:
using ModularSystem.Core;
namespace MyApp;
public class MyUseCase
{
public async Task DoSomeStuff()
{
using var service = new UserService();
var user = new User();
var id = await service.CreateAsync(user);
}
public async Task DoSomeMoreStuff()
{
using var service = new UserService();
var query = new QueryWriter<User>()
.SetFilter(user => user.Email == "foo@bar.baz")
.OrFilter(user => user.Email == "bar@foo.baz")
.SetOrdering(user => user.Id)
.SetOrderingDirection(OrderingDirection.Ascending)
.Create();
var queryResult = await service.QueryAsync(query);
}
}
API Controller
Create a basic CRUD API with the ApiController base class, which generates GET, POST, PUT, and DELETE endpoints.
Example:
using ModularSystem.Core;
using ModularSystem.Web;
namespace MyApp;
[Route("api/user")]
public class UserController : CrudController<User>
{
protected override EntityService<User> Service => new UserService();
}
Accessing the API with a CRUD Client from another C# application.
You can access the API created by the CrudController through an instance of CrudClient<T>.
Note: For seamless communication, it's crucial that both applications either reference the same resource assembly or have exact replicas of it. In this context, the User
class is the shared resource. It's imperative that the shared resource has a matching type fullname. For instance, the class MyApp.User
should be present in both applications, even if they reside in separate assemblies or originate from different version sources.
Example (client app):
using ModularSystem.Core;
using ModularSystem.Web;
using MyApp;
namespace MyClientApp;
public class Program
{
public static async Task Main()
{
var config = new EndpointConfiguration("https://localhost:5001/api/user");
var userClient = new CrudClient<User>(config);
var query = new QueryWriter<User>()
.SetFilter(user => user.Email == "foo@bar.baz")
.CreateSerializable();
var queryResult = await userClient.QueryAsync(query);
}
}
WORK IN PROGRESS...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 7.0.11)
- Microsoft.EntityFrameworkCore.Sqlite (>= 7.0.11)
- MongoDB.Driver (>= 2.21.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on ModularSystem.Core:
Package | Downloads |
---|---|
PlataformaOmega.IntegrationLibrary
Package Description |
|
Webql
... |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.40.0-prerelease.8 | 120 | 1/10/2024 |
1.40.0-prerelease.7 | 137 | 11/14/2023 |
1.40.0-prerelease.6 | 83 | 11/2/2023 |
1.40.0-prerelease.5 | 83 | 10/20/2023 |
1.40.0-prerelease.4 | 75 | 10/16/2023 |
1.40.0-prerelease.3 | 75 | 10/16/2023 |
1.40.0-prerelease.2 | 78 | 10/16/2023 |
1.40.0-prerelease.1 | 70 | 10/15/2023 |
1.39.1 | 201 | 9/28/2023 |
1.39.0 | 144 | 9/28/2023 |
1.38.2 | 131 | 9/27/2023 |
1.38.1 | 145 | 9/25/2023 |
1.38.0 | 132 | 9/19/2023 |
1.37.3 | 160 | 9/18/2023 |
1.37.2 | 108 | 9/18/2023 |
1.37.1 | 129 | 9/18/2023 |
1.37.0 | 164 | 9/13/2023 |
1.36.0 | 177 | 9/12/2023 |
1.35.6 | 157 | 9/12/2023 |
1.35.5 | 159 | 9/12/2023 |
1.35.4 | 165 | 9/11/2023 |
1.35.3 | 156 | 9/7/2023 |
1.35.2 | 140 | 9/6/2023 |
1.35.1 | 158 | 9/6/2023 |
1.35.0 | 163 | 9/6/2023 |
1.35.0-prerelease.42 | 98 | 8/31/2023 |
1.35.0-prerelease.41 | 78 | 8/31/2023 |
1.35.0-prerelease.40 | 99 | 8/30/2023 |
1.35.0-prerelease.39 | 92 | 8/30/2023 |
1.35.0-prerelease.38 | 98 | 8/29/2023 |
1.35.0-prerelease.37 | 89 | 8/27/2023 |
1.35.0-prerelease.36 | 84 | 8/26/2023 |
1.35.0-prerelease.35 | 84 | 8/26/2023 |
1.35.0-prerelease.34 | 81 | 8/26/2023 |
1.35.0-prerelease.33 | 80 | 8/26/2023 |
1.35.0-prerelease.32 | 87 | 8/25/2023 |
1.35.0-prerelease.31 | 98 | 8/25/2023 |
1.35.0-prerelease.30 | 89 | 8/25/2023 |
1.35.0-prerelease.29 | 88 | 8/25/2023 |
1.35.0-prerelease.28 | 82 | 8/25/2023 |
1.35.0-prerelease.27 | 86 | 8/25/2023 |
1.35.0-prerelease.26 | 78 | 8/25/2023 |
1.35.0-prerelease.25 | 85 | 8/25/2023 |
1.35.0-prerelease.24 | 84 | 8/25/2023 |
1.35.0-prerelease.23 | 91 | 8/24/2023 |
1.35.0-prerelease.22 | 89 | 8/24/2023 |
1.35.0-prerelease.21 | 82 | 8/23/2023 |
1.35.0-prerelease.20 | 80 | 8/23/2023 |
1.35.0-prerelease.19 | 78 | 8/23/2023 |
1.35.0-prerelease.18 | 91 | 8/19/2023 |
1.35.0-prerelease.17 | 84 | 8/19/2023 |
1.35.0-prerelease.16 | 93 | 8/19/2023 |
1.35.0-prerelease.15 | 78 | 8/18/2023 |
1.35.0-prerelease.14 | 84 | 8/16/2023 |
1.35.0-prerelease.13 | 81 | 8/16/2023 |
1.35.0-prerelease.12 | 85 | 8/15/2023 |
1.35.0-prerelease.11 | 93 | 8/14/2023 |
1.35.0-prerelease.10 | 92 | 8/13/2023 |
1.35.0-prerelease.9 | 92 | 8/13/2023 |
1.35.0-prerelease.8 | 96 | 8/9/2023 |
1.35.0-prerelease.7 | 107 | 8/2/2023 |
1.35.0-prerelease.6 | 94 | 8/2/2023 |
1.35.0-prerelease.5 | 101 | 8/2/2023 |
1.35.0-prerelease.4 | 86 | 8/2/2023 |
1.35.0-prerelease.2 | 126 | 8/1/2023 |
1.35.0-prerelease.1 | 103 | 7/25/2023 |
1.34.3 | 184 | 7/14/2023 |
1.34.2 | 205 | 7/11/2023 |
1.34.1 | 186 | 7/11/2023 |
1.34.0 | 151 | 7/11/2023 |
1.33.1 | 183 | 7/6/2023 |
1.33.0 | 187 | 7/6/2023 |
1.32.7 | 184 | 5/31/2023 |
1.32.6 | 239 | 5/31/2023 |
1.32.5 | 180 | 5/31/2023 |
1.32.4 | 172 | 5/31/2023 |
1.32.3 | 189 | 5/30/2023 |
1.32.2 | 233 | 5/30/2023 |
1.32.1 | 224 | 5/30/2023 |
1.32.0 | 165 | 5/26/2023 |
1.31.6 | 204 | 4/25/2023 |
1.31.5 | 210 | 4/25/2023 |
1.31.4 | 287 | 4/24/2023 |
1.31.3 | 222 | 4/21/2023 |
1.31.2 | 192 | 4/20/2023 |
1.31.1 | 134 | 4/14/2023 |
1.31.0 | 196 | 4/6/2023 |
1.30.0 | 133 | 4/4/2023 |
1.29.18 | 455 | 3/18/2023 |
1.29.17 | 334 | 3/18/2023 |
1.29.16 | 262 | 3/16/2023 |
1.29.15 | 262 | 3/16/2023 |
1.29.14 | 250 | 3/14/2023 |
1.29.13 | 534 | 3/9/2023 |
1.29.12 | 526 | 3/6/2023 |
1.29.11 | 272 | 3/3/2023 |
1.29.10 | 264 | 3/3/2023 |
1.29.9 | 358 | 3/2/2023 |
1.29.8 | 349 | 3/2/2023 |
1.29.7 | 625 | 3/1/2023 |
1.29.6 | 261 | 3/1/2023 |
1.29.5 | 357 | 2/27/2023 |
1.29.4 | 270 | 2/27/2023 |
1.29.3 | 281 | 2/25/2023 |
1.29.2 | 294 | 2/24/2023 |
1.29.1 | 307 | 2/24/2023 |
1.29.0 | 286 | 2/24/2023 |
1.28.4 | 273 | 2/22/2023 |
1.28.3 | 367 | 2/18/2023 |
1.28.2 | 287 | 2/18/2023 |
1.28.1 | 296 | 2/17/2023 |
1.28.0 | 453 | 2/16/2023 |
1.27.0 | 294 | 2/8/2023 |
1.26.3 | 303 | 2/7/2023 |
1.26.2 | 304 | 2/7/2023 |
1.26.1 | 293 | 2/7/2023 |
1.26.0 | 301 | 2/6/2023 |
1.25.21 | 311 | 2/4/2023 |
1.25.20 | 417 | 2/4/2023 |
1.25.19 | 308 | 2/4/2023 |
1.25.18 | 305 | 2/4/2023 |
1.25.17 | 295 | 2/3/2023 |
1.25.16 | 325 | 2/3/2023 |
1.25.15 | 302 | 1/28/2023 |
1.25.14 | 313 | 1/28/2023 |
1.25.13 | 313 | 1/27/2023 |
1.25.12 | 343 | 1/27/2023 |
1.25.11 | 473 | 1/27/2023 |
1.25.10 | 331 | 1/27/2023 |
1.25.9 | 412 | 1/20/2023 |
1.25.8 | 350 | 1/20/2023 |
1.25.7 | 348 | 1/20/2023 |
1.25.6 | 359 | 1/20/2023 |
1.25.5 | 328 | 1/20/2023 |
1.25.4 | 406 | 1/20/2023 |
1.25.3 | 330 | 1/20/2023 |
1.25.2 | 328 | 1/20/2023 |
1.25.1 | 337 | 1/19/2023 |
1.25.0 | 351 | 1/19/2023 |
1.24.4 | 579 | 1/13/2023 |
1.24.3 | 362 | 1/13/2023 |
1.24.2 | 340 | 1/13/2023 |
1.24.1 | 365 | 1/13/2023 |
1.24.0 | 341 | 1/13/2023 |
1.23.0 | 601 | 9/14/2022 |
1.22.0 | 505 | 8/27/2022 |
1.21.0 | 487 | 8/16/2022 |
1.20.1 | 522 | 8/4/2022 |
1.20.0 | 643 | 7/23/2022 |
1.19.3 | 532 | 7/8/2022 |
1.19.2 | 542 | 7/8/2022 |
1.19.1 | 932 | 7/7/2022 |
1.19.0 | 513 | 7/7/2022 |
1.18.10 | 658 | 7/6/2022 |
1.18.9 | 944 | 7/2/2022 |
1.18.8 | 514 | 7/2/2022 |
1.18.7 | 544 | 7/2/2022 |
1.18.6 | 540 | 7/2/2022 |
1.18.5 | 517 | 7/2/2022 |
1.18.4 | 514 | 7/2/2022 |
1.18.3 | 515 | 7/1/2022 |
1.18.2 | 527 | 6/28/2022 |
1.18.1 | 563 | 6/28/2022 |
1.18.0 | 507 | 6/27/2022 |
1.17.0 | 538 | 6/27/2022 |
1.16.8 | 554 | 5/16/2022 |
1.16.7 | 564 | 5/12/2022 |
1.16.6 | 568 | 5/10/2022 |
1.16.5 | 585 | 5/10/2022 |
1.16.4 | 566 | 5/10/2022 |
1.16.3 | 562 | 5/10/2022 |
1.16.2 | 586 | 4/30/2022 |
1.16.1 | 575 | 4/30/2022 |
1.16.0 | 573 | 4/30/2022 |
1.15.2 | 581 | 4/28/2022 |
1.15.1 | 566 | 4/27/2022 |
1.15.0 | 1,511 | 4/27/2022 |
1.14.8 | 584 | 4/1/2022 |
1.14.7 | 592 | 4/1/2022 |
1.14.6 | 600 | 4/1/2022 |
1.14.5 | 553 | 4/1/2022 |
1.14.4 | 620 | 3/27/2022 |
1.14.3 | 573 | 3/26/2022 |
1.14.2 | 585 | 3/25/2022 |
1.14.1 | 1,018 | 3/23/2022 |
1.14.0 | 567 | 3/23/2022 |
1.13.1 | 603 | 3/22/2022 |
1.13.0 | 580 | 3/22/2022 |
1.12.2 | 581 | 3/22/2022 |
1.12.1 | 772 | 3/22/2022 |
1.12.0 | 574 | 3/22/2022 |
1.11.2 | 614 | 3/11/2022 |
1.11.1 | 602 | 3/10/2022 |
1.11.0 | 583 | 3/10/2022 |
1.10.0 | 733 | 3/7/2022 |
1.9.2 | 631 | 3/3/2022 |
1.9.1 | 601 | 3/3/2022 |
1.9.0 | 1,677 | 2/26/2022 |
1.8.3 | 587 | 2/26/2022 |
1.8.2 | 605 | 2/1/2022 |
1.8.1 | 609 | 1/24/2022 |
1.8.0 | 617 | 1/24/2022 |
1.7.1 | 660 | 1/19/2022 |
1.7.0 | 614 | 1/19/2022 |
1.6.0 | 609 | 1/19/2022 |
1.5.0 | 634 | 1/19/2022 |
1.4.3 | 511 | 1/14/2022 |
1.4.2 | 508 | 1/14/2022 |
1.4.1 | 616 | 1/13/2022 |
1.4.0 | 511 | 1/13/2022 |
1.3.0 | 657 | 1/12/2022 |
1.2.0 | 516 | 1/11/2022 |
1.1.3 | 526 | 1/11/2022 |
1.1.2 | 510 | 1/11/2022 |
1.1.1 | 520 | 1/11/2022 |
1.1.0 | 518 | 1/11/2022 |
Pre release of API breaking changes.