Circular Project Reference Issue

Ok, I have three projects in the solution thus far:

Venue.Domain
Venue.Infrastructure
Venue.Resources

Venue.Resources houses some resx files for localized strings. Venue.Infrastructure house a lot of things, but for this issue, it’s the Specifications namespace that is causing problems.

Take the following entity method:

public virtual void AddForum(IPrincipal user, Forum forum)
{
 
// this is ok
if (new IsAdministrator().Not().IsSatisfiedBy(user))
throw new Exception(Locale.user_is_not_authorized);
 
// this is okif (new IsNull().IsSatisfiedBy(forum))
throw new Exception(Locale.forum_is_required);
 
// this needs an IList<Forum> so it balks
if (new ForumAlreadyPresent(forums).IsSatisfiedBy(forum))
throw new Exception(Locale.duplicate_forum_found);
 
forums.Add(forum);
}

The entities need to reference the specs, but, as you can see, some of the specs need to reference the entities.

Solution?

Nevermind! This was my fix:

using System.Collections.Generic;
namespace Venue.Infrastructure.Specifications.Constraints
{
    public class IsInList<T> : Specification<T> 
    {
        private IList<T> list;
        public IsInList(IList<T> list)
        {
            this.list = list;
        }
        public override bool IsSatisfiedBy(T candidate)
        {
            return list.Contains(candidate);
        }
    }
}

Now I can do this from the entities:

if (new IsInList<Forum>(Forums).IsSatisfiedBy(forum))
throw new Exception(Locale.duplicate_item_found);

Problem solved.