0% found this document useful (0 votes)
58 views

Creating The Infrastructure Project: Gill Cleeren

This document discusses creating the infrastructure project for an application. It explains that the infrastructure layer contains all external components like the database, files, services, and logging. It describes adding Entity Framework Core for data persistence using DbContext and migrations. It also discusses implementing a base repository and specific repositories. Finally, it mentions adding the ability to send emails through SendGrid by creating an interface in the core project and implementing it in infrastructure along with registering the service. The document demonstrates some of these tasks and emphasizes splitting infrastructure into separate projects based on their target.

Uploaded by

Manehcmis Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Creating The Infrastructure Project: Gill Cleeren

This document discusses creating the infrastructure project for an application. It explains that the infrastructure layer contains all external components like the database, files, services, and logging. It describes adding Entity Framework Core for data persistence using DbContext and migrations. It also discusses implementing a base repository and specific repositories. Finally, it mentions adding the ability to send emails through SendGrid by creating an interface in the core project and implementing it in infrastructure along with registering the service. The document demonstrates some of these tasks and emphasizes splitting infrastructure into separate projects based on their target.

Uploaded by

Manehcmis Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Creating the Infrastructure Project

Gill Cleeren
CTO XPIRIT BELGIUM

@gillcleeren www.snowball.be
Overview
Understanding the goal of the
infrastructure projects
Adding Entity Framework Core
Implementing other infrastructure tasks
Understanding the Goal
of the Infrastructure Projects
The Infrastructure Layer

All external or I/O components


User interface
- Database
• EF Core
• DbContext
- Files
Interfaces
Entities - Service bus
- Service client
Application Core - Logging

Infrastructure
The Infrastructure Layer

Configuration of technical frameworks


User interface
Implementations for contracts defined
in the Core project
Reference to Core project
Interfaces - Through dependency inversion and
Entities
dependency injection, services get
implemented
Application Core

Infrastructure
Adding Data Persistence with
Entity Framework Core
Adding EF Core

NuGet packages DbContext Migrations Startup


registration
Repository
implementations
Generic repository contract in
Core project

Base repository implementation

Specific repositories if needed


Base Repository

public class BaseRepository<T> : IAsyncRepository<T> where T : class


{

protected readonly GloboTicketDbContext _dbContext;

public BaseRepository(GloboTicketDbContext dbContext)


{

_dbContext = dbContext;
}

public virtual async Task<T> GetByIdAsync(Guid id)


{

return await _dbContext.Set<T>().FindAsync(id);


}
}
Specific Repositories

public class CategoryRepository : BaseRepository<Category>, ICategoryRepository


{

public CategoryRepository(GloboTicketDbContext dbContext) : base(dbContext)


{ }

public async Task<List<Category>> GetCategoriesWithEvents ()


{
//TODO: include implementation here
}
}
Demo
Adding the Persistence project
Bringing in support for EF Core
Demo Adding the base repository
implementation
Adding specific repositories
Registering services in the
ServiceCollection
“Oh, I forgot to mention this in the
previous meeting…
We’ll need to send a mail when an event
has been created. Can this be added?”
Implementing Other Infrastructure Tasks
Sending a Mail Through SendGrid

Infrastructure code to send a NuGet package in


mail Infrastructure

Implementation in
Interface in Core project
Infrastructure
Creating the Infrastructure project
Demo Writing the mail service using SendGrid
API
Using the code from the Application
Core code
Registering the mail service in the
ServiceCollection
Summary
Infrastructure contains all configuration
for external services
Split up in 2 projects, based on their
target
Up next:
Creating the API
using ASP.NET Core

You might also like