Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is it ok to design the scheduler in this way with a background thread?</p> </blockquote> <p>Sure. As long as everything is thread-safe. From a DI perspective there is no problem, but of course you need to make sure that shared dependencies are thread-safe (as you must do with all multi-threaded applications). However, when the service is performant / fast enough without multi-threading, make the application single-threaded. This makes everything so much easier.</p> <blockquote> <p>By using a different design, could this coupling be reduced further or is this coupling acceptable?</p> </blockquote> <p>Possibly. Your <code>CronJobService</code> takes a dependency on the <code>Container</code>. This is not a problem, as long as it is part of the <a href="http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx" rel="nofollow noreferrer">Composition Root</a>. However, your <code>CronJobService</code> contains a lot of logic, which means you probably want to test it, but this is hard since you coupled it with the container and <code>Task.Factory</code>. Separate this if you can.</p> <p>The use of a <code>IUnitOfWorkFactory</code> can be fine (take a look at <a href="https://stackoverflow.com/questions/10585478/one-dbcontext-per-web-request-why/10588594#10588594">this SO question and answer</a> for instance). But since you already have a <code>IUnitOfWork</code> registered Per Lifetime Scope, I don't really see how a <code>IUnitOfWorkFactory</code> helps. So instead of calling the <code>CreateUnitOfWork</code> inside the <code>SomeBackgroundLoop</code>, you can just wrap this method with a <code>using (container.BeginLifetimeScope())</code>. This way this method runs inside the context of a lifetime scope, which means that any injected <code>IUnitOfWork</code> (within this thread) will be the same unit of work.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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