Structuremap and creating objects with initial state
Posted
by
Simon
on Stack Overflow
See other posts from Stack Overflow
or by Simon
Published on 2011-01-03T18:35:26Z
Indexed on
2011/01/03
18:53 UTC
Read the original article
Hit count: 199
I have an object which needs a dependency injected into it
public class FootballLadder
{
public FootballLadder(IMatchRepository matchRepository, int round)
{
// set initial state
this.matchRepo = matchRepository;
this.round = round;
}
public IEnumerable<LadderEntry> GetLadderEntries()
{
// calculate the ladder based on matches retrieved from the match repository
// return the calculated ladder
}
private IMatchRepository matchRepo;
private int round;
}
For arguments sake, lets assume that I can't pass the round parameter into the GetLadderEntries call itself.
Using StructureMap, how can I inject the dependency on the IMatchRepository and set the initial state? Or is this one of those cases where struggling against the framework is a sign the code should be refactored?
© Stack Overflow or respective owner