Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a solution, still not sure if it's the best one. Seems kind of like brute force to me. </p> <p>The first thing I did was combine my Metadata classes into the same project / library as my Entity classes. Since my repository interface is IRepository&lt;T&gt;, the repository needed to be declared as IRepository&lt;UserEntity&gt;. This resolved the circular dependency I was talking about. Now I have UserEntity [depends on] UserMetadata [depends on] DuplicateUserValidationAttribute [depends on] DuplicateUserValidator [depends on] UserEntity. With all of these classes in the same library, though there is still circularity, there are no circular assembly dependencies. </p> <p>The second thing I did was wrap my IUnityContainer into a singleton and moved it to my cross-cutting utilities library (before it existed only in the MVC 3 project). </p> <p>Then, in my DuplicateUserValidator constructor, I could do the following:</p> <pre><code>public class DuplicateUserValidator : Micrsoft.Practices.EnterpriseLibrary.Validation.Validator&lt;string&gt; { public IRepository&lt;UserEntity&gt; UserRepository { get; set; } public DuplicateUserValidator(string tag) : base(string.Empty, tag) { IUnityContainer unity = UnityContainerSingleton.Get(); this.UserRepository = unity.Resolve&lt;IRepository&lt;UserEntity&gt;&gt;() as IRepository&lt;UserEntity&gt;; } } </code></pre> <p>Now I have a repository dependency injected into the custom entlib validator implementation. Wish I could get unity to automatically inject it into the constructor, maybe I'll look into that next. </p>
 

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