1

I have a class:

Question

With the properties:

Bool IsTextAnswer
List<String> Answers

The answers to a question are: 2-4 answers stored in the list of answers OR 4 colors (stored in the db, for every question the same). The boolean decides if the answers are from the list or the colors.

The colors are just a table in the database with 4 rows, for every color a row. These colors aren't linked to anything so I made a new repository: colorRepository from which I can get all the colors.

I did this in my code: Constructor

public Question(IColorRepository colorRepository) {
   _colorRepository = colorRepository;
}

In the getter of the answers I try to do something like this:

if(IsTextAnswers) 
    return answers
return _colorRepository.FindAll

But ninject doesn't work because it's not a controller so I get the message that there is no parameterless constructor.

How can I retrieve my 4 colors from the database?

I only need the be able to read from the database, the questions + answers are made by an administrator in a java program.

Joachim
  • 173
  • 1
  • 8
  • Related: http://stackoverflow.com/questions/1405665/how-should-i-handle-my-entity-domain-objects-using-ioc-dependency-injection – Steven May 02 '13 at 13:37
  • Related: http://stackoverflow.com/questions/4835046/why-not-use-an-ioc-container-to-resolve-dependencies-for-entities-business-objec – Steven May 02 '13 at 13:38

1 Answers1

1

It looks like Question is an entity, and entity framework needs it to have a parameterless constructor.

Your repository should be a separate class, the domain objects should be POCOs and not have data access code in them.

Joe Ratzer
  • 18,176
  • 3
  • 37
  • 51