Skip to content

Commit

Permalink
feat: Agrego inyección de dependencia
Browse files Browse the repository at this point in the history
Agrego el servicio fibonacci al startup.cs

issue: #9
  • Loading branch information
Gonzalo Guimaraens committed Aug 21, 2019
1 parent 634425e commit dbaf35b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/FibonacciWebApi/Controllers/FiboController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace FibonacciWebApi.Controllers
[ApiController]
public class FiboController : ControllerBase
{
private readonly Services.IFiboService FiboService;

public FiboController(Services.IFiboService pFiboService)
{
FiboService = pFiboService;
}

// GET: api/Fibo
[HttpGet]
public IEnumerable<string> Get()
Expand All @@ -22,8 +29,8 @@ public IEnumerable<string> Get()
[HttpGet("{i}")]
public long CalcularFibonacci(int i)
{
Services.IFiboService serv = new Services.FiboService();
long res = serv.CalcularFibonacci(i);

long res = FiboService.CalcularFibonacci(i);
return res;

}
Expand Down
2 changes: 1 addition & 1 deletion src/FibonacciWebApi/Services/IFiboService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FibonacciWebApi.Services
{
interface IFiboService
public interface IFiboService
{
long CalcularFibonacci(int i);
}
Expand Down
1 change: 1 addition & 0 deletions src/FibonacciWebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddScoped<Services.IFiboService, Services.FiboService>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down

0 comments on commit dbaf35b

Please sign in to comment.