Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
From definition:
> Inversion of Control (IoC) means to create instances of dependencies first and latter instance of a class (optionally injecting them through constructor)

is then it a good example of DI and IoC?
Meaning that I create instance in startup (IoC) and then inject it through constructor (DI)? I have hard time understanding IoC, but this seems to be the simpliest example.

also from this article https://auth0.com/blog/dependency-injection-in-dotnet-core/ it seems that
ILogger
is built in example, am I right?

What I have tried:

I have code in
Startup.cs


 public void ConfigureServices(IServiceCollection services)
{
   string connectionString = Configuration.GetConnectionString("DbConnection");
            services.AddDbContext<AppDbContext>(options => options.UseSqlServer(connectionString));
   services.AddControllersWithViews();
   services.AddScoped<IBooksService, BooksService>();
   services.AddScoped<IBooksRepository, BooksRepository>();
}

and e.g. controller:

 public BookController(IBooksService booksService, ILogger<BookController> logger)
{
  _booksService = booksService;
  _logger = logger;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900