Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if StructureMap has a specific type configured?

Tags:

structuremap

Is there a way to determine if a specific type has been configured in StructureMap?

I want to return a generic type if it has not be specifically configured in StructureMap.

like image 258
Jon Cahill Avatar asked Jan 05 '09 06:01

Jon Cahill


2 Answers

In v2.6 you want:

IContainer.Model.HasImplementationsFor(serviceType)
like image 192
Andrew Bullock Avatar answered Nov 09 '22 21:11

Andrew Bullock


From StructureMap version 2.5.1 there is a TryGetInstance<T>() and TryGetNamedInstance<T>() which will return the default value of T if T is not known.

like image 24
Jon Cahill Avatar answered Nov 09 '22 22:11

Jon Cahill