Skip to content

Generics

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

Stashbox supports the registration of open generic types, and concrete generic service creation from them with generic parameter constraint checking:

interface IDrow<TLeftHand, TRightHand> 
{
	//...
}

class Drow<TLeftHand, TRightHand> : IDrow<TLeftHand, TRightHand> 
{
	public Drow(TLeftHand leftHand, TRightHand rightHand)
	{
		//...
	}
}

container.RegisterType(typeof(IDrow<,>), typeof(Drow<,>));
container.RegisterType<Twinkle>();
container.RegisterType<Icingdeath>();

//resolution
var drizzt = container.Resolve<IDrow<Twinkle, Icingdeath>>();