title: Unity Container Dependency Injection - How Would I Register This?
body: <p>I have an interface, ICrudService, and a service that implements the interface, CrudService. I am trying to use Unity for dependency injection purposes, but I can't see to figure out how to register the type.</p>
  
  <p>Here is my ICrudService:</p>
  
  <pre><code>public interface ICrudService&lt;T&gt; where T: DelEntity, new()
  {
      int Create(T item);
      void Save();
  
      T Get(int id);
      IEnumerable&lt;T&gt; GetAll();
      IEnumerable&lt;T&gt; Where(Expression&lt;Func&lt;T, bool&gt;&gt; func, bool showDeleted = false);
  }
  </code></pre>
  
  <p>Here is my CrudService:</p>
  
  <pre><code>public class CrudService&lt;T&gt; : ICrudService&lt;T&gt; where T : DelEntity, new ()
  {
      protected IRepo&lt;T&gt; repo;
  
      public CrudService(IRepo&lt;T&gt; repo)
      {
          this.repo = repo;
      }
  
      public IEnumerable&lt;T&gt; GetAll()
      {
          return repo.GetAll();
      }
  
      public T Get(int id)
      {
          return repo.Get(id);
      }
  
      public virtual int Create(T item)
      {
          var newItem = repo.Insert(item);
          repo.Save();
          return newItem.Id;
      }
  
      public void Save()
      {
          repo.Save();
      }
  
      public virtual void Delete(int id)
      {
          repo.Delete(repo.Get(id));
          repo.Save();
      }
  
      public void Restore(int id)
      {
          repo.Restore(repo.Get(id));
          repo.Save();
      }
  
      public void BatchDelete(int[] ids)
      {
          foreach (var id in ids)
          {
              repo.Get(id).IsDeleted = true;
          }
  
          repo.Save();
      }
  
      public void BatchRestore(int[] ids)
      {
          foreach (var id in ids)
          {
              repo.Get(id).IsDeleted = false;
          }
  
          repo.Save();
      }
  
      public IEnumerable&lt;T&gt; Where(Expression&lt;Func&lt;T, bool&gt;&gt; predicate, bool showDeleted = false)
      {
          return repo.Where(predicate, showDeleted);
      }
  }
  </code></pre>
  
  <p>And finally, my UnitConfig.cs, which I can't even get to build...</p>
  
  <pre><code>public class UnityConfig
  {
      #region Unity Container
      private static Lazy&lt;IUnityContainer&gt; container = new Lazy&lt;IUnityContainer&gt;(() =&gt;
      {
          var container = new UnityContainer();
          RegisterTypes(container);
          return container;
      });
  
      /// &lt;summary&gt;
      /// Gets the configured Unity container.
      /// &lt;/summary&gt;
      public static IUnityContainer GetConfiguredContainer()
      {
          return container.Value;
      }
      #endregion
  
      /// &lt;summary&gt;Registers the type mappings with the Unity container.&lt;/summary&gt;
      /// &lt;param name="container"&gt;The unity container to configure.&lt;/param&gt;
      /// &lt;remarks&gt;There is no need to register concrete types such as controllers or API controllers (unless you want to 
      /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.&lt;/remarks&gt;
      public static void RegisterTypes(IUnityContainer container)
      {
          // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
          // container.LoadConfiguration();
  
          // TODO: Register your types here
          container.RegisterType&lt;ICrudService&lt;T&gt;, CrudService&lt;T&gt;&gt;();
      }
  }
  </code></pre>
  
  <p>What am I doing wrong in the UnityConfig.cs?</p>