title: Autofac dependency injection implementation
body: <p>I started working on a new project and I come from a direct and 'naive' programming.</p>
  
  <p>Right now I'm concerning about using IoC container, specifically on Dependency Injection patter using Autofac.</p>
  
  <p>Let's say I have a simple session factory : </p>
  
  <pre><code>namespace Warehouse.Data
  {
      public class SessionFactory
      {
          private static ISessionFactory _sessionFactory;
          private static ISystemSetting _systemSetting;
  
          SessionFactory(ISystemSetting systemSetting)
          {
              _systemSetting = systemSetting;
  
              InitializeSessionFactory();
          }
  
          private static void InitializeSessionFactory()
          {
              _sessionFactory = Fluently.Configure()
                  .Database(DatabaseConfiguration)
                  .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;MyMap&gt;())
                  .BuildSessionFactory();
          }
  
          public static ISession OpenSession()
          {
              return _sessionFactory.OpenSession();
          }
      }
  }
  </code></pre>
  
  <p>And in Bootstrap.cs, I configure autofac like this : </p>
  
  <pre><code>namespace Warehouse.Infrastructure
  {
      using Autofac;
  
      public class Bootstrap
      {
          public IContainer Configure()
          {
              var builder = new ContainerBuilder();
  
              builder.RegisterType&lt;SystemSetting&gt;().As&lt;ISystemSetting&gt;();
              builder.RegisterType&lt;UserRepository&gt;().As&lt;IUserRepository&gt;();
  
              return builder.Build();
          }
      }
  }
  </code></pre>
  
  <p>My question is this : </p>
  
  <ol>
  <li>How do I use Autofac to resolve SessionFactory dependency to ISystemSetting?
  Do I need to use <code>builder.Resolve&lt;ISystemSetting&gt;</code> as a parameter everytime I want to use SessionFactory?</li>
  <li>Dependency Injection pattern, or maybe just Autofac, comes with lots of new word such as Service, Resolve, Singleton, etc. Where can I learn these things from scratch? Is it the same for every other DI Framework?</li>
  <li>I need to understand how IoC Container works in a project with multiple layer, do every layer needs a reference to Autofac?</li>
  </ol>
  
  <p>Thank you.</p>