F2.Repository 8.0.11.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package F2.Repository --version 8.0.11.1                
NuGet\Install-Package F2.Repository -Version 8.0.11.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="F2.Repository" Version="8.0.11.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add F2.Repository --version 8.0.11.1                
#r "nuget: F2.Repository, 8.0.11.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install F2.Repository as a Cake Addin
#addin nuget:?package=F2.Repository&version=8.0.11.1

// Install F2.Repository as a Cake Tool
#tool nuget:?package=F2.Repository&version=8.0.11.1                

F2.Repository

Codacy Badge

Simple definitions for repository pattern

Getting started

1. Install Nuget package F2.Repository

Install-Package F2.Repository

2. Implement IEntity<TKey> on your models

Or, you can create your own BaseEntity:

public abstract class BaseEntity : IEntity<Guid>, ITimestampedEntity
{
	public Guid Id { get; set; }
	public DateTime CreatedAt { get; set; }
	public DateTime UpdatedAt { get; set; }
}
public class Book : BaseEntity
{
    public string Title { get; set; }

    public string Isbn { get; set; }

	public virtual ICollection<Author> Authors { get; set; }
}

Create your configuration (see example)

public class BookEntityConfiguration : IEntityTypeConfiguration<Book>
{
	public void Configure(EntityTypeBuilder<Book> builder)
	{
		builder.UseAutoGeneratedId();
		builder.UseTimestampedProperty();

		builder.HasMany(s => s.Authors).WithMany(s => s.Books);
	}
}

3. Implement your repository

GenericEntityRepository<TEntityType> or GenericRepository<TEntityType> abstracts

using F2.Repository.Abstracts;

public class CustomerRepository : GenericEntityRepository<Customer>
{
    public CustomerRepository(YourDbContext context) : base(context)
    {
    }
}

4. Create Database Context Scope

public class YourDbScope : DbContextScope<YourDbContext>
{
    public YourDbScope(YourDbContext context) : base(context)
    {
        YourRepository = yourRepository;
    }

    public YourRepository YourRepository { get; }
}

5. Register Scope and repositories to DI

All repositories will automatically registered for DI

services.AddDatabaseScope<YourDbContext>();
// ... services.AddDbContext<AutomateContext>(opts => opts.UseSqlServer(_configuration.GetConnectionString("SqlConnection"));
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on F2.Repository:

Package Downloads
F2.Infrastructure

Basic infrastructure

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.11.3 80 11/15/2024
8.0.11.1 74 11/14/2024
8.0.11 74 11/14/2024
8.0.6 128 7/4/2024