dependency injection - Register multiple interfaces that has explicit implementation on a single instance -
i using autofac , not ioc master.
consider scenario:
public interface ibeforerequesttask { void execute(); } public interface iafterrequesttask { void execute(); } public class taskexecutor : ibeforerequesttask, iafterrequesttask { void ibeforerequesttask.execute() { // code } void iafterrequesttask.execute() { // code } }
so, have explicit implementations. how register these interfaces?
i think can't this:
builder.registertype<ibeforerequesttask> ... builder.registertype<iafterrequesttask> ...
i read in autofac registration docs must register concrete types.
similar question not treating autofac one: tinyioc: register multiple interfaces on single instance
well, know can easy doing 1-1 (one interface per class, register concrete type). curious it.
don't remeber saw below code using structuremap (can wrong):
action.addtypesof<ibeforerequesttask>(); action.addtypesof<iafterrequesttask>();
hope made myself clear. thank all.
edit
created this sample help. ;-)
i'm not sure want achieve if want register single class available in container under 2 interfaces , want have single instance of can this.
builder.registertype<taskexecutor>().as<ibeforerequesttask>().as<iafterrequesttask>().singleinstance();
Comments
Post a Comment