Skip to content

Multi resolution

Peter Csajtai edited this page Feb 16, 2017 · 13 revisions

Stashbox allows you to resolve all the available services bound to an interface or base class.

container.RegisterType<ICreature, Dwarf>("Bruenor");
container.RegisterType<ICreature, Drow>("Drizzt");
container.RegisterType<ICreature, Human>("Catti-brie");
container.RegisterType<ICreature, Barbarian>("Wulfgar");
container.RegisterType<ICreature, Halfling>("Regis");

Then you can get all of your services by calling the ResolveAll() method.

var companionsOfTheHall = container.ResolveAll<ICreature>();

Or you can just let Stashbox to do the work for you.

class CompanionsOfTheHall
{
	public CompanionsOfTheHall(IEnumerable<ICreature> members)
	{
		//...
	}
	
	//or
	
	public CompanionsOfTheHall(ICreature[] members)
	{
		//...
	}

        //or
	
	public CompanionsOfTheHall(ICollection<ICreature> members)
	{
		//...
	}
 
        //etc...
}

//or

var companions = container.Resolve<IEnumerable<ICreature>>();
//etc...