From efce79512efa5338c81d6b27de414f970605383c Mon Sep 17 00:00:00 2001 From: activehigh Date: Mon, 19 May 2025 16:47:33 +1000 Subject: [PATCH 1/2] update docs --- README.md | 32 ---------- docs/README.md | 50 ++++++++++++++++ docs/usage.md | 155 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 32 deletions(-) delete mode 100644 README.md create mode 100644 docs/README.md create mode 100644 docs/usage.md diff --git a/README.md b/README.md deleted file mode 100644 index 8104444..0000000 --- a/README.md +++ /dev/null @@ -1,32 +0,0 @@ - -# Build Status -![](https://github.com/Activehigh/Atl.GenericRepository/workflows/Atl%20Generic%20Repository%20-%20Build%20&%20Test/badge.svg) - -# A generic repository for .net platform - -A Lightweight EF Core Repository. More changes comming. - -# Supported Platform - -|Platform |Version | -|----------|:-------------| -|.Net Standard |2.0+| - -# Installation -``` -Install-Package Atl.Repository.Standard -``` -OR -``` -dotnet add package Atl.Repository.Standard -``` - -# Basic Usage -[Atl.Repository.Standard – Basic Usage](https://activehigh.wordpress.com/2017/08/13/atl-repository-standard-basic-usage/) -# Advanced Usage -[Atl.Repository.Standard – Using IoC Or A DI Container](https://brainlesscoder.com/2019/03/21/atl-repository-standard-using-ioc-or-a-di-container/) - - -# License - -Available as open source under the terms of the [MIT License](LICENSE). diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..d73d478 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,50 @@ +# Atl.Repository.Standard + +A flexible and powerful generic repository pattern implementation for .NET applications that supports dependency injection, multi-tenancy, and domain-driven design principles. + +## Overview + +Atl.Repository.Standard is a robust implementation of the repository pattern that helps developers maintain a clean and maintainable data access layer. It provides a standardized way to handle database operations while supporting advanced features like: + +- Multi-tenancy support for data isolation +- Built-in dependency injection +- Support for multiple assemblies +- Customizable unit of work patterns +- Domain-driven design principles +- Parallelism and concurrency handling + +## Installation + +### NuGet Package + +```bash +# Using .NET CLI +dotnet add package Atl.Repository.Standard + +# Using Package Manager Console +Install-Package Atl.Repository.Standard +``` + +### Required Dependencies + +The package requires the following dependencies: +- Microsoft.EntityFrameworkCore (>= 6.0.0) +- Microsoft.Extensions.DependencyInjection (>= 6.0.0) + +## Features + +- Generic CRUD operations +- Built-in support for Dependency Injection +- Multi-tenancy support +- Parallelism and concurrency support +- Customizable unit of work patterns +- Domain-driven design friendly +- Support for multiple assemblies + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. + +## Author + +Mahmudul Islam - [@activehigh](https://activehigh.wordpress.com/) diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 0000000..21c454d --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,155 @@ +# Atl.Repository.Standard + +A flexible and powerful generic repository pattern implementation for .NET applications that supports dependency injection, multi-tenancy, and domain-driven design principles. + +## Features + +- Generic CRUD operations +- Built-in support for Dependency Injection +- Multi-tenancy support +- Parallelism and concurrency support +- Customizable unit of work patterns +- Domain-driven design friendly +- Support for multiple assemblies + +## Basic Usage + +### 1. Setup Domain Classes + +First, create your domain classes inheriting from `BaseDomain`: + +```csharp +public abstract class BaseDomain +{ + public virtual int Id { get; set; } + public virtual bool IsActive { get; set; } + public virtual bool IsDeleted { get; set; } + public virtual bool IsLocked { get; set; } + public virtual bool IsArchived { get; set; } + public virtual bool IsSuspended { get; set; } + public virtual DateTime? CreatedAt { get; set; } + public virtual DateTime? UpdatedAt { get; set; } +} + +public class Tenant : BaseDomain, IDomain +{ + // Your tenant properties +} +``` + +### 2. Required Components + +#### Id Generator +```csharp +// Use built-in implementations +var idGenerator = new IdentityKeyGenerator(); // For int keys +// or +var idGenerator = new GuidKeyGenerator(); // For Guid keys +``` + +#### Domain Injector +```csharp +public class DomainInjector : IDomainInjector +{ + public void InjectDomain(ModelBuilder modelBuilder) + { + modelBuilder.Entity(); + } +} +``` + +#### System Clock +```csharp +var clock = new DefaultSystemClock(); +``` + +#### Configuration Provider +```csharp +public class TestConfigurationProvider : IConfigurationProvider +{ + public string ConnectionString => ""; + public DbContextOptionsBuilder ApplyDatabaseBuilderOptions(DbContextOptionsBuilder optionsBuilder) + { + var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "TestDatabase.db" }; + return optionsBuilder.UseSqlite(connectionStringBuilder.ToString()); + } +} +``` + +#### Database Context Factory +```csharp +var configurationProvider = new TestConfigurationProvider(); +var domainInjector = new DomainInjector(); +var contextFactory = new DomainContextFactory( + new List() { domainInjector }, + configurationProvider +); +``` + +### 3. Create Repository +```csharp +var repository = new Repository(idGenerator, contextFactory, clock); +``` + +## Advanced Usage with Dependency Injection + +### 1. Install Required Package +```bash +dotnet add package Microsoft.Extensions.DependencyInjection +``` + +### 2. Configure Services +```csharp +var serviceCollection = new ServiceCollection(); + +// Register repository components +serviceCollection.AddTransient, DomainContextFactory>(); +serviceCollection.AddTransient(); +serviceCollection.AddTransient, IdentityKeyGenerator>(); +serviceCollection.AddTransient(); +serviceCollection.AddTransient(); +serviceCollection.AddTransient(typeof(IGenericRepository<>), typeof(Repository<>)); + +// Build service provider +var serviceProvider = serviceCollection.BuildServiceProvider(); +``` + +### 3. Use in Services +```csharp +public class OrderService : IOrderService +{ + private readonly IGenericRepository _repository; + + public OrderService(IGenericRepository repository) + { + _repository = repository; + } + + public List GetActiveOrders() + { + return _repository.GetAll() + .Where(x => x.IsActive) + .OrderBy(x => x.CreatedAt) + .ToList(); + } +} +``` + +## Working with Related Entities + +You can easily work with related entities using Include: + +```csharp +// Example with Organization and Tenant +public class Organization : BaseDomain +{ + public Tenant Tenant { get; set; } + public int TenantId { get; set; } +} + +// Query with includes +var organizations = _repository.GetAll() + .Include(x => x.Tenant) + .Where(x => x.Tenant.Name == "Some Tenant") + .ToList(); +``` From ad138375cc4939c744acdd3aca2e221237163229 Mon Sep 17 00:00:00 2001 From: activehigh Date: Mon, 19 May 2025 16:48:48 +1000 Subject: [PATCH 2/2] update docs --- docs/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/README.md b/docs/README.md index d73d478..cc18438 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,6 +13,10 @@ Atl.Repository.Standard is a robust implementation of the repository pattern tha - Domain-driven design principles - Parallelism and concurrency handling +For detailed usage instructions, please refer to: +- [Basic Usage Guide](https://activehigh.wordpress.com/2019/03/18/atl-repository-standard-basic-usage/) +- [Advanced Usage with Dependency Injection](https://activehigh.wordpress.com/2019/03/21/atl-repository-standard-using-ioc-or-a-di-container/) + ## Installation ### NuGet Package