title: How to properly inject dependencies with the built in Funq container?
body: <p>I have a cached repository  </p>
  
  <pre><code>public interface IRepository
  {
      void LogWebUsage(string html);
      IEnumerable&lt;ApiKey&gt; GetApiKeys();
      ApiKey GetApiKey(Guid key);
  }
  
  public class Repository : IRepository
  {
      private static readonly ILog Log = LogManager.GetLogger("API.Repository");
  
      public IDbConnectionFactory DbFactory { get; set; }
  
      public void LogWebUsage(string request)
      {
          Log.Debug(request);
      }
  
      public virtual IEnumerable&lt;ApiKey&gt; GetApiKeys()
      {
          List&lt;ApiKey&gt; result = null;
          using (var db = DbFactory.OpenDbConnection())
          {
              result = db.SelectParam&lt;ApiKey&gt;(q =&gt; q.Active);
          }
  
          return result;
      }
  
      public ApiKey GetApiKey(Guid key)
      {
          ApiKey result = null;
          using (var db = DbFactory.OpenDbConnection())
          {
              result = (db.SelectParam&lt;ApiKey&gt;(q =&gt; q.Id == key)).FirstOrDefault();
          }
  
          return result;
      }
  }
  
  public class CachedRepository : Repository
  {
      public ICacheClient Cache { get; set; }
  
      public override IEnumerable&lt;ApiKey&gt; GetApiKeys()
      {
          const string cacheKey = "GetApiKeys";
  
          var result = Cache.Get&lt;IEnumerable&lt;ApiKey&gt;&gt;(cacheKey);
  
          if (result == null)
          {
              result = base.GetApiKeys();
  
              if (result.Any())
              {
                  Cache.Add(cacheKey, result, TimeSpan.FromMinutes(30));
              }
          }
          return result;
      }
  }
  </code></pre>
  
  <p>And I configure it like so.</p>
  
  <pre><code>//Register any dependencies you want injected into your services
  container.Register&lt;IDbConnectionFactory&gt;(new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("DBConnstr"), true, SqlServerOrmLiteDialectProvider.Instance));
  container.Register&lt;ICacheClient&gt;(new MemoryCacheClient());
  container.Register&lt;IRepository&gt;(new CachedRepository());
  container.RegisterAutoWired&lt;CachedRepository&gt;();
  </code></pre>
  
  <p>So what I was hoping for is that both the IDbConnectionFactory and ICacheClient would be injected at run-time, but they are null. How to you properly account for this type of dependency graph?</p>
  
  <p>Thank you,
  Stephen</p>
  
  <p><strong>Updated</strong></p>
  
  <p>After googling for a couple of hours I finally found a solution that works. Constructor injection though the config.</p>
  
  <pre><code>public class CachedRepository : Repository
  {
      private ICacheClient Cache { get; set; }
  
      public CachedRepository(IDbConnectionFactory dbFactory, ICacheClient cache) : base(dbFactory)
      {
          Cache = cache;
      }
  
      public override IEnumerable&lt;ApiKey&gt; GetApiKeys()
      {
          const string cacheKey = "GetApiKeys";
  
          var result = Cache.Get&lt;IEnumerable&lt;ApiKey&gt;&gt;(cacheKey);
  
          if (result == null)
          {
              result = base.GetApiKeys();
  
              if (result.Any())
              {
                  Cache.Add(cacheKey, result, TimeSpan.FromMinutes(30));
              }
          }
          return result;
      }
  }
  </code></pre>
  
  <p>Configuration</p>
  
  <pre><code>//Register any dependencies you want injected into your services
  container.Register&lt;IDbConnectionFactory&gt;(c =&gt; new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("DBConnstr"), true, SqlServerOrmLiteDialectProvider.Instance));        
  container.Register&lt;ICacheClient&gt;(c =&gt; new MemoryCacheClient());
  container.Register&lt;IRepository&gt;(c =&gt; new CachedRepository(c.Resolve&lt;IDbConnectionFactory&gt;(), c.Resolve&lt;ICacheClient&gt;()));
  </code></pre>
  
  <p>It works, but I'd still like to know how to wire up the property injection.</p>
  
  <p>Take care,
  Stephen... again</p>