title: Autofac's None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'
body: <p>I'm back to Autofac issues despite using it in a very similar manner for over a year and really need some advise.</p>
  
  <p>I choose to opt-in via attributes.  The difference this time is that one of the registrations uses IIndex to select the most appropriate interface for the task at hand based on a LoginState enum.  This value is provided via the attribute .  </p>
  
  <p>You could consider it a very basic Autofac based state-machine.</p>
  
  <p>Due to the opt-in nature I have the following extension method which gets the type via the presence of the attribute and the value of the attribute:</p>
  
  <pre><code>public static class ContainerBuilderEnumerateAttributedTypes
  {
      #region EnumerateAttributedTypes(builder, action)
  
      [DebuggerStepThrough]
      public static void EnumerateAttributedTypes&lt;TAttribute&gt;(this ContainerBuilder builder,
          Action&lt;Type, TAttribute&gt; action) where TAttribute : Attribute
      {
          var typesAndAttributes = Assembly
              .GetExecutingAssembly()
              .GetTypes()
              .Where(type =&gt; type.GetCustomAttributes&lt;TAttribute&gt;(false).Any())
              .Select(type =&gt; new { Type = type, Attribute = type.GetCustomAttributes&lt;TAttribute&gt;(false).First() });
  
          foreach (var typeAndAtttribute in typesAndAttributes)
          {
              action(typeAndAtttribute.Type, typeAndAtttribute.Attribute);
          }
      }
  
      #endregion
  
      #region EnumerateAttributedTypes(builder, inherit, action)
  
      [DebuggerStepThrough]
      public static void EnumerateAttributedTypes&lt;TAttribute&gt;(this ContainerBuilder builder,
          bool inherit, Action&lt;Type, TAttribute&gt; action) where TAttribute : Attribute
      {
          var typesAndAttributes = Assembly
              .GetExecutingAssembly()
              .GetTypes()
              .Where(type =&gt; type.GetCustomAttributes&lt;TAttribute&gt;(inherit).Any())
              .Select(type =&gt; new { Type = type, Attribute = type.GetCustomAttributes&lt;TAttribute&gt;(inherit).First() });
  
          foreach (var typeAndAtttribute in typesAndAttributes)
          {
              action(typeAndAtttribute.Type, typeAndAtttribute.Attribute);
          }
      }
  
      #endregion
  }
  </code></pre>
  
  <p>During Global.asax.cs I call builder.RegisterModule which in terms calls builder.RegisterModule.</p>
  
  <p>In there I have the following:</p>
  
  <pre><code>public class LogicAutofacModule : Module
  {
      #region Load
  
      protected override void Load(ContainerBuilder builder)
      {
          builder.EnumerateAttributedTypes&lt;DispatcherAttribute&gt;((type, attribute) =&gt;
          {
              var @interface = type.GetInterfaces().First();
  
              //  ReSharper disable once ConvertToLambdaExpression
              builder
                  .RegisterType(type)
                  .As(@interface);
          });
  
          builder.EnumerateAttributedTypes&lt;LogicAttribute&gt;((type, attribute) =&gt;
          {
              var @interface = type.GetInterfaces().First();
  
              //  ReSharper disable once ConvertToLambdaExpression
              builder
                  .RegisterType(type)
                  .Keyed(attribute.State, @interface)
                  .As(@interface);
          });
      }
  
      #endregion
  </code></pre>
  
  <p>There are two instances of IDispatcher are:</p>
  
  <pre><code>IIndex&lt;LoginState, ILogic&lt;AuthenticateContext, AuthenticateResult&gt;&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>IIndex&lt;LoginState, ILogic&lt;AuthenticateIncurringChargeContext, AuthenticateIncurringChargeResult&gt;&gt; _handlers; 
  </code></pre>
  
  <p>The LoginState if specified via a attribute, when applicable, via a </p>
  
  <p>[LogicDispatcher(LogicState.InvalidCredentials)]</p>
  
  <p>and similar.</p>
  
  <p>No matter how I do this, even falling back to the most basic way of registering I get the 'None of the constructors found with </p>
  
  <pre><code>Autofac.Core.Activators.Reflection.DefaultConstructorFinder error message.
  </code></pre>
  
  <p>Never had this before... please advise or ask for more info.</p>
  
  <p>Afterthought...  here is an example of the ILogic implementation:</p>
  
  <pre><code>[Logic(LoginState.InvalidAccount)]
  public class AuthenticateInvalidAccount : ILogic&lt;AuthenticateContext, AuthenticateResult&gt;
  {
      #region Execute
  
      public AuthenticateResult Execute(AuthenticateContext context, LoginResponse response)
      {
          return new AuthenticateResult
          {
              State = State.InvalidAccount
          };
      }
  
      #endregion
  }
  </code></pre>
  
  <p>And an instance of a dispatcher:</p>
  
  <pre><code>[Dispatcher]
  public class AuthenticateDispatcher : IDispatcher&lt;AuthenticateContext, AuthenticateResult&gt;
  {
      #region Fields
  
      private readonly IIndex&lt;LoginState, ILogic&lt;AuthenticateContext, AuthenticateResult&gt;&gt; _handlers; 
  
      #endregion
  
      #region Constructors
  
      public AuthenticateDispatcher(IIndex&lt;LoginState, ILogic&lt;AuthenticateContext, AuthenticateResult&gt;&gt; handlers)
      {
          _handlers = handlers;
      }
  
      #endregion
  
      #region Dispatch
  
      public AuthenticateResult Dispatch(AuthenticateContext context)
      {
          var service = new AccountServiceClient();
  
          var response = service.Invoke(client =&gt; client.Login(context.Username, context.Password));
  
          var logic = _handlers[response.LoginState];
  
          var result = logic.Execute(context, response);
  
          return result;
      }
  
      #endregion
  }
  </code></pre>
  
  <p>The service super simple:</p>
  
  <pre><code>[ErrorHandled]
  public class Service : IService
  {
      #region Fields
  
      private readonly IDispatcher&lt;AuthenticateContext, AuthenticateResult&gt; _authenticateDispatcher;
  
      private readonly IDispatcher&lt;AuthenticateIncurringChargeContext, AuthenticateIncurringChargeResult&gt; _authenticateIncurringChargeDispatcher;
  
      #endregion
  
      #region Constructor
  
      public Service(
          IDispatcher&lt;AuthenticateContext, AuthenticateResult&gt; authenticateDispatcher,
          IDispatcher&lt;AuthenticateIncurringChargeContext, AuthenticateIncurringChargeResult&gt; authenticateIncurringChargeDispatcher)
      {
          _authenticateDispatcher = authenticateDispatcher;
          _authenticateIncurringChargeDispatcher = authenticateIncurringChargeDispatcher;
      }
  
      #endregion
  
      #region Authenticate
  
      public AuthenticateResponse Authenticate(AuthenticateRequest request)
      {
          var context = request.Map&lt;AuthenticateContext&gt;();
  
          var result = _authenticateDispatcher.Dispatch(context);
  
          var response = result.Map&lt;AuthenticateResponse&gt;();
  
          return response;
          throw new NotImplementedException();
      }
  
      #endregion
  
      #region AuthenticateIncurringCharge
  
      public AuthenticateIncurringChargeResponse AuthenticateIncurringCharge(AuthenticateIncurringChargeRequest request)
      {
          //var context = request.Map&lt;AuthenticateIncurringChargeContext&gt;();
  
          //var result = _authenticateIncurringChargeDispatcher.Dispatch(context);
  
          //var response = result.Map&lt;AuthenticateIncurringChargeResponse&gt;();
  
          //return response;
          throw new NotImplementedException();
      }
  
      #endregion
  }
  </code></pre>