Carl Bussema
Carl Bussema

Reputation: 1714

Dependencies waiting to be satisifed

I'm trying to abstract some simple tasks for some very simple objects.

In my domain model, there are a number of different objects which basically serve as a way to tag (classify) a "Program." The Business Logic says a program can have as many of these as its wants, but no tags of the same type (e.g., "County") can have the same name, and you can't delete a tag while it has programs linked to it.

This is built on MVC3 with S#arp 2.0.

The domain model has an abstract base class NamedEntity : Entity which defines public string Name { get; set; } among other properties.

Specific types extend this class to add whatever makes them unique (if anything), such as Topic, which is a heirarchical structure and so has additional properties for that.

I wanted to create INamedEntityTasks<T> where T: NamedEntity and then have a base version of this for handling routine tasks like bool CheckForDuplicateName(string Name) which would run access its INamedEntityQueries<T> object and call T FindByName(string Name)

If a subclass needed to add more rules prior to delete (e.g. a topic with children can't be deleted), then it just overrides the virtual method from the base class.

Structure:

My TopicsController won't run because of a missing dependency that I can't figure out.

The exact exception is

Can't create component 'MyProject.web.mvc.controllers.topicscontroller' as it has dependencies to be satisfied. MyProject.web.mvc.controllers.topicscontroller is waiting for the following dependencies:

Services: - MyProject.Infrastructure.Queries.ITopicQueries which was not registered. - MyProject.Domain.Contracts.Tasks.ITopicTasks which was registered but is also waiting for dependencies.

MyProject.Tasks.TopicTasks is waiting for the following dependencies:

Services: - MyProject.Infrastructure.Queries.INamedEntityQueries`1[[MyProject.Domain.Topic, MyProject.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] which was not registered.

I checked the container in ComponentRegistrar with a breakpoint and it shows 3 potentially misconfigured:

"MyProject.Tasks.NamedEntityTasks`1" NamedEntityTasks`1
"MyProject.Tasks.TopicTasks" ITopicTasks / TopicTasks
"MyProject.web.mvc.controllers.topicscontroller" TopicsController`TopicsController`

Any help would be appreciated.

Upvotes: 3

Views: 4892

Answers (1)

ChrisR
ChrisR

Reputation: 1338

You don't need the IFooTasks interface, just use an abstract base class, then IFooBarTasks and IFooBazTasks will be registered with Castle Windsor by the standard ComponentRegistrar in S#arp Architecture:

public abstract class Foo
{
  public void Foo1();

  public void Foo2();
}

public class FooBar : Foo
{
  public void FooBar1();
}

public class FooBaz : Foo
{
  public void FooBaz1();
}

public interface IFooTasks
{
  void Foo1();

  void Foo2();
}

public interface IFooBarTasks : IFooTasks
{
  void FooBar1();
}

public interface IFooBazTasks : IFooTasks
{
  void FooBaz1();
}

public abstract class FooTasks : IFooTasks
{
  public void Foo1()
  {
    // Foo1 implementation
  }

  public void Foo2()
  {
    // Foo2 implementation
  }
}

public class FooBarTasks : FooTasks, IFooBarTasks
{
  public void FooBar1()
  {
    // FooBar1 implementation
  }
}

public class FooBazTasks : FooTasks, IFooBazTasks
{
  public void FooBaz1()
  {
    // FooBaz1 implementation
  }
}

Upvotes: 2

Related Questions