title: Autofac PropertiesAutowired - Is it possible to ignore a one or more properties?
body: <p>Despite the advice to pass dependencies through the constructor I've found that the development cost of having parameterless constructors and then autowiring all of the properties on everything is significantly less and makes the application much easier to develop out and maintain. However sometimes (on a view model for example) I have a property that is registered with the container, but that I don't want to populate at construction (for example the selected item bound to a container).</p>
  
  <p>Is there any way to tell the container to ignore certain properties when it autowires the rest?</p>
  
  <p>At the moment I'm just resetting the properties marked with an attribute in the on activated event a la:</p>
  
  <pre><code>public static IRegistrationBuilder&lt;TLimit, ScanningActivatorData, TRegistrationStyle&gt; 
      PropertiesAutowiredExtended&lt;TLimit, TRegistrationStyle&gt;(
      this IRegistrationBuilder&lt;TLimit, ScanningActivatorData, TRegistrationStyle&gt; builder)
  {
      builder.ActivatorData.ConfigurationActions.Add(
          (type, innerBuilder) =&gt;
          {
              var parameter = Expression.Parameter(typeof(object));
              var cast = Expression.Convert(parameter, type);
              var assignments = type.GetProperties()
                  .Where(candidate =&gt; candidate.HasAttribute&lt;NotAutowiredAttribute&gt;())
                  .Select(property =&gt; new { Property = property, Expression = Expression.Property(cast, property) })
                  .Select(data =&gt; Expression.Assign(data.Expression, Expression.Default(data.Property.PropertyType)))
                  .Cast&lt;Expression&gt;()
                  .ToArray();
  
              if (assignments.Any())
              {
                  var @action = Expression
                      .Lambda&lt;Action&lt;object&gt;&gt;(Expression.Block(assignments), parameter)
                      .Compile();
  
                  innerBuilder.OnActivated(e =&gt;
                  {
                      e.Context.InjectUnsetProperties(e.Instance);
                      @action(e.Instance);
                  });
              }
              else
              {
                  innerBuilder.OnActivated(e =&gt; e.Context.InjectUnsetProperties(e.Instance));
              }
          });
  
      return builder;
  }
  </code></pre>
  
  <p>Is there a better way to do this?</p>