The Sharp Factory
Esc
↑ ↓ to moveEnter to open
Getting Started / Dependency Injection

Dependency Injection

Register the repository container with the .NET dependency injection container.

.NET 10#

Setting up Dependency Injection is easy.

The RepositoryContainer class is the only class that needs to be injected and it implements the IRepositoryContainer interface.

The code below illustrates how to set up DI in the Program.cs file of a .NET 10 application. Console and worker apps do the same with Host.CreateApplicationBuilder.

C#
// Replace SFDemo with the root namespace// specified when you first generated the modelusing SFDemo.Repository.Common;using SFDemo.Repository.Container;using SFDemo.Repository.Container.Interfaces;var builder = WebApplication.CreateBuilder(args);// setup dependency injection as a singletonbuilder.Services.AddSingleton<IRepositoryContainer, RepositoryContainer>();// the rest of your code goes here..........var app = builder.Build();app.Run();