Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glass.Mapper.Sc set inferType to true by default globally

In Glass.Mapper.Sc v 4.0.1.5 ISitecoreService and ISitecoreContext have all their method signatures with inferType default to false. I'm looking for a way to override that and default to true without changing the method calls all over the site.

I created another interface to override those just to modify the inferType default to true but I was wondering if there's a better solution.

like image 995
Mark Saad Avatar asked Nov 21 '25 13:11

Mark Saad


1 Answers

There isn't an automatic override to do this but it might be simpler to create your own task in the configuration resolver pipeline.

If you look at the following line of code: https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/Pipelines/ConfigurationResolver/TemplateInferredTypeTask.cs#L48

You can see that it just checks for the InferType flag, you could create another pipeline at the start of the request that just sets this to true. Every request would then be force through InferType.

You will need to register your new pipeline process in the GlassMapperScCustom against the DependencyResolver.ConfigurationResolverFactory using the Add method.

like image 74
Michael Edwards Avatar answered Nov 23 '25 03:11

Michael Edwards