illyW-Framework is a .NET framework that provides a set of utilities to facilitate application development by implementing some of the most common and powerful patterns like:
- Generic Entity
- Repository
- Unit of Work
- Result
This framework aims to reduce boilerplate code by offering generic implementations that can be easily extended or integrated into existing projects.
You can install illyW-Framework via NuGet. Run the following command in the Package Manager Console:
Install-Package illyW.Framework.Core
Install-Package illyW.Framework.EFCore
The IEntity interface is a base interface which can be implemented to create entities with common identifiers.
public class TestEntity : IEntity<int>
{
public int Id { get;set; }
public string Name { get; set; }
}
public class TestEntity2 : IEntity<string>
{
public string Id { get;set; }
public string Name { get; set; }
}
The IGenericRepository interface provides a set of methods to support CRUD operations.
public interface ITestRepository : IGenericRepository<TestEntity, int>;
public class TestCoreDbContext(DbContextOptions options) : DbContext(options)
{
public DbSet<TestEntity> TestEntities { get; set; } = null!;
}
public class TestRepository(TestCoreDbContext context)
: GenericRepository<TestEntity, int, TestCoreDbContext>(context), ITestRepository;
serviceCollection.AddRepository<ITestRepository, TestRepository>();
[ApiController]
[Route("api/[controller]")]
public class TestController(ITestRepository repository) : ControllerBase
{
[HttpGet]
public ActionResult GetAll()
{
return Ok(repository.Fetch());
}
}
The IUnitOfWork interface provides a set of methods to centralize the management of transactional operations, ensuring that changes are applied atomically.
serviceCollection.AddUnitOfWork<TestCoreDbContext>();
[ApiController]
[Route("api/[controller]")]
public class TestController(IUnitOfWork uow) : ControllerBase
{
[HttpPost]
public ActionResult Create([FromBody] string name)
{
var repository = uow.GetRepository<ITestRepository>();
var repository2 = uow.GetRepository<ITest2Repository>();
var r1 = await repository.AddAsync(new TestEntity {Name = name});
var r2 = await repository2.AddAsync(new TestEntity2 {Name = name});
if(r1.IsSuccessful && r2.IsSuccesful)
{
uow.Commit();
return Ok();
}
return UnprocessableEntity();
}
}
The IResult is an interface to represent the outcome of an operation, enabling elegant handling of success, failure, and status messages.