Skip to content

Commit

Permalink
feat : add mediatR
Browse files Browse the repository at this point in the history
  • Loading branch information
SAgiKPJH committed Apr 13, 2024
1 parent 497a498 commit 95fb718
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MovieManagement.Library.Models;
using MovieManagement.Library.Queries;

namespace MovieManagement.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MoviesController : ControllerBase
{
private readonly IMediator _mediator;

public MoviesController(IMediator mediator)
{
_mediator = mediator;
}

// Get: api/<MoviesController>
[HttpGet]
public async Task<List<MovieModel>> Get()
=> await _mediator.Send(new GetMovieListQuery());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\" />
<ProjectReference Include="..\MovieManagement.Library\MovieManagement.Library.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions MovieManagement.API/MovieManagement.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using MovieManagement.Library.Data;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
Expand All @@ -7,6 +11,9 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddScoped<IDataRepository, DataRepository>();
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(typeof(DataRepository).Assembly));

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand Down

0 comments on commit 95fb718

Please sign in to comment.