5

In the implementation using Glass Mapper 4.3.x, I was enabling Lazy Loading in GlassMapperScCustom:

public static IDependencyResolver CreateResolver(){
            var config = new Glass.Mapper.Sc.Config();

            config.EnableLazyLoadingForCachableModels = true;

            var dependencyResolver = new DependencyResolver(config);

            var factory = dependencyResolver.ObjectConstructionFactory as AbstractConfigFactory<AbstractObjectConstructionTask>;
            factory.Remove<ModelDepthCheck>();

            return dependencyResolver;
        }

This hid some recursive model references and sloppy model properties. I am looking for an easy way to re-enable before doing a large re-factorization.

Is this possible in Glass Mapper v5?

Thanks

6

In version 5 config.EnableLazyLoadingForCachableModels setting was removed and "IsLazy"-setting was removed from all model property configuration, like

[SitecoreChildren(IsLazy = false)]
IEnumerable<ISitecoreItem> Children{get;set;}

You should just remove all these settings from your models, because of in V5 lazy loading was improved (it is enabled by default and disabled when request or model is cachable) and your model cann`t be a mix of lazy and non-lazy parts.

In version 5 you can force disable/enable lazy loading only when you retrieve your model, like

var data = _mvcContext.GetDataSourceItem<IData>(x => x.LazyDisabled());

or

var data = _sitecoreService.GetItem<IData>(Constants.Data.ID, x => x.LazyEnabled());

Almost all glassmapper interfaces has this parameter.

But I think that for your case it will be enough just to remove old settings when you upgrade to version 5 (at least there were no troubles on our project).

These links may be helpful:

http://glass.lu/Mapper/GettingStarted

http://glass.lu/Blog/V5

  • Thanks. This is a case of, "Don't fight it, just rewrite it." I have been working on removing recursive model properties and data expensive model properties. Its a few days worth of work but no getting around it. – Tom Paterno Feb 8 at 13:42
  • Thank you. Can I use more than one such methods at the same time? For instance if I want LazyDisabled, but also InferType()? – Emanuele Ciriachi Aug 27 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.