JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
572 stars 119 forks source link

Get parent type in labda expression #155

Closed elendil-software closed 5 years ago

elendil-software commented 5 years ago

Hi,

With StructureMap I was able to to something like :

For<ILogger>().Use(context => Log.Logger.ForContext("context", context.ParentType.FullName, false));

This doesn't seem to exist anymore in Lamar, the context doesn't contain the property ParentType. Is there an alternative ?

Regards

jeremydmiller commented 5 years ago

Lamar is never going to support that feature from StructureMap. Instead, I'd recommend using a constructor policy to add an explicit logger constructor argument based on the parent type so this is baked in at "planning" time instead of being a runtime decision. See the docs at https://jasperfx.github.io/lamar/documentation/ioc/registration/policies/ for more information.

elendil-software commented 5 years ago

Perfect, Thanks.