Commit 4382139b authored by Almouhannad's avatar Almouhannad

(B) Update assemblies references, and link them to program.cs

parent ead3c9e3
......@@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
......
using API.Options.Database;
using Domain.Repositories.Base;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Persistence.Context;
using Persistence.Repositories.Base;
var builder = WebApplication.CreateBuilder(args);
......@@ -32,15 +30,29 @@ builder.Services.AddDbContext<ClinicsDbContext>(
// Add services to the container.
#region Link repositories
// AddTransient: Created on demand, every time they are requested, not shared across requests or components.
builder.Services.AddTransient(typeof(IRepository<>), typeof(Repositroy<>));
#region Link interfaces implemented in persistence
// Using Scrutor library
builder
.Services
.Scan(
selector => selector
.FromAssemblies(Persistence.AssemblyReference.Assembly
// Add other assemblies here
)
.AddClasses(false)
.AsImplementedInterfaces()
.WithScopedLifetime()
);
#endregion
#region Add MadiatR
builder.Services.AddMediatR(configuration =>
configuration.RegisterServicesFromAssembly(Application.AssemblyReference.Assembly));
#endregion
#region Link controllers with presentation layer
var presentationAssembly = typeof(Presentation.AssemblyReference).Assembly;
builder.Services.AddControllers()
.AddApplicationPart(presentationAssembly);
.AddApplicationPart(Presentation.AssemblyReference.Assembly);
#endregion
......
using System.Reflection;
namespace Application;
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
using System.Reflection;
namespace Persistence;
public class AssemblyReference
{
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
namespace Presentation
using System.Reflection;
namespace Presentation;
public class AssemblyReference
{
public class AssemblyReference
{
}
public static readonly Assembly Assembly = typeof(AssemblyReference).Assembly;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment