AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

DI / IoC

Open Rick-Anderson opened this issue 11 years ago • 13 comments

port my DI doc from HTML to reStructuredText

Rick-Anderson avatar Apr 08 '15 22:04 Rick-Anderson

looking forward to it :dancers:

dougbu avatar Apr 09 '15 03:04 dougbu

ASP.NET 5->Runtime->Dependency Injection •Adding services: singleton, scoped, transient •Default behavior: constructor injection •Using a your favorite IoC Container

danroth27 avatar Apr 21 '15 05:04 danroth27

Waiting with bated breath for the Using your favorite IoC container info.

tdietrich513 avatar May 14 '15 16:05 tdietrich513

@tdietrich513 While you are waiting check out what the Autofac guys published on how to use Autofac with ASP.NET 5: http://alexmg.com/autofac-4-0-alpha-1-for-asp-net-5-0-beta-3/

danroth27 avatar May 14 '15 16:05 danroth27

Nice- my preferred container is Windsor but maybe I can hack out an implementation until they get on their game.

tdietrich513 avatar May 14 '15 16:05 tdietrich513

Planning on starting this today/tomorrow, @danroth27. Update TOC if necessary and/or set up a meeting to discuss, please. Otherwise planning on working from Rick's DI/IOC article as a base.

ardalis avatar Sep 09 '15 19:09 ardalis

How to get framework services from DI

  • Ex ILoggerFactory
  • Ex DbContext

How to add services to the DI system

  • Ex Repository pattern that injects the DbContext
  • Service lifetime: transient, scoped, singleton
  • Registration: type, factory, instance

Request services vs application services

Core services available from hosting during startup

  • IHostingEnvironment
  • ILoggerFactory
  • IApplicationEnvironment
  • ??

Replacing the default IoC container with your favorite one

  • Example: https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Startup.cs
  • http://www.nuget.org/packages/Autofac.Dnx/4.0.0-alpha2

What should go in DI?

  • DI is for creating objects with complex dependencies, not for storing application data
  • Ex you wouldn't put the user's shopping cart in DI, you might put a shopping cart factory

Anti-patterns

  • Static access to services or HttpContext

danroth27 avatar Sep 17 '15 17:09 danroth27

@danroth27 How i can help write this documentation?

nicolastakashi avatar Sep 28 '15 19:09 nicolastakashi

@nicolastakashi you can review my PR that's coming shortly

ardalis avatar Sep 28 '15 19:09 ardalis

@ardalis Seems great!

Do you wanna talk by skype or email? How do you prefer?

nicolastakashi avatar Sep 28 '15 19:09 nicolastakashi

@nicolastakashi I think just using PR comments (once I get the PR done in a few days) will work fine.

ardalis avatar Oct 01 '15 18:10 ardalis

Hello, I'm very interested in reviewing any early material on how the Dependency Injection module that will be a part of ASP.NET 5.0 is going to be working. I'm happy to spend a little extra time making notes to the author. My intention is to jump into ASP.NET 5.0 a lot earlier than I've jumped into previous bleeding edge .net releases, so feel free to utilize me to bounce revisions off.

mattchristenson avatar Nov 14 '15 03:11 mattchristenson

@mattchristenson @nicolastakashi shoot me an email [email protected] and I'll send you the latest version (in a zipped HTML file). You can then comment on this PR

Rick-Anderson avatar Nov 14 '15 06:11 Rick-Anderson