I want to have StructureMap return a Special Case called "None" for a certain instance.
Say I Have this class MyUser
which is scoped as HttpContext. I want to have a nested, dreived class None
(ie. MyUser.None
) which is returtned for the type MyUser
when there is no HttpContext
(for example, like in bootstrapping, Application_Start()
etc).
This would mean that certain calls could check for the Special Case type instead of null (more readable) like
if(value is MyUser.None)
// do special case things
else
// do normal case things
What SM config do I need to achieve this? I have tried the ConditionallyUse
method without much success. I keep getting NullReferenceExceptionS
throwing from within SM itself.