Using preloading Attribute Configuration

There are times, for example when using inferred types, that you will want to preload your attribute configured classes. This ensures that all the types that you have marked up are loaded by Glass.Mapper before you do any work.

If you install the Glass.Mapper.Sc.CastleWindsor nuget into your project and then looking at the App_Start/GlassMapperScCustom class we can find the following code:

		public static IConfigurationLoader[] GlassLoaders(){
			
			
			return new IConfigurationLoader[]{};
		}

With this  setup classes will only be configured when they are requested by your code. Instead we want to force Glass.Mapper to load all your classes when the application starts. This can be simply achieved by adding SitecoreAttributeConfigurationLoader's which takes the name of an assembly to scan:

		public static IConfigurationLoader[] GlassLoaders(){
            var attributes = new SitecoreAttributeConfigurationLoader("GlassExamples.Website");
            var attributes2 = new SitecoreAttributeConfigurationLoader("GlassExamples.Business");
			
			return new IConfigurationLoader[]{attributes, attributes2};
		}

You can also configure you fluent configuration loaders here as well, see Tutorial 8 - Fluent configuration