Note that there are some explanatory texts on larger screens.

plurals
  1. POautofac: component registration being ignored
    primarykey
    data
    text
    <p>The following class takes a primitive on the constructor, so I need to tell AutoFac how to generate said value using a delegate:</p> <pre><code>public class BackgroundTaskScheduler : IStartable { private readonly IJobRunner _jobRunner; private int _triggerMilliseconds; public BackgroundTaskScheduler(IJobRunner jobRunner, int triggerMilliseconds) { _jobRunner = jobRunner; _triggerTimespan = triggerMilliseconds; } } public static class AutoFac { public static void Configure() { var builder = new ContainerBuilder(); var triggerInterval = int.Parse( ConfigurationManager.AppSettings["TaskScheduleTriggerMilliseconds"]); builder.Register( c =&gt; new BackgroundTaskScheduler(c.Resolve&lt;IJobRunner&gt;(), triggerInterval)).AsImplementedInterfaces().SingleInstance(); builder.RegisterAssemblyTypes(typeof (RegistrationController).Assembly) .AsImplementedInterfaces() .AsSelf(); IContainer container = builder.Build(); } } </code></pre> <p>However, Autofac appears to ignore my registration as evidenced by the exception it throws when resolving an instance of <code>BackgroundTaskScheduler</code>:</p> <p><strong>None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Delen.Server.Tasks.BackgroundTaskScheduler' can be invoked with the available services and parameters: Cannot resolve parameter 'System.Int32 triggerMilliseconds' of constructor 'Void .ctor(Delen.Server.Tasks.IJobRunner, System.Int32)'.</strong></p> <p>I've successfully used the <code>IContainerBuilder.Register</code> method before in exactly such a scenario but I've no clue why it's not working this go around. </p> <p><strong>Update 1</strong></p> <p>Changing the order of the registrations did not make a difference. </p> <p><strong>Update 2</strong></p> <p>Here's an alternative way to achieve the same result as the accepted Answer: </p> <pre><code>builder.RegisterAssemblyTypes(typeof(IJobRunner).Assembly) .Except&lt;BackgroundTaskScheduler&gt;() .AsImplementedInterfaces() .AsSelf() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload