Just a quick post to pick up on one of the improvements that has been added to the Sitecore ItemBinding Framework.
When the framework was first release it was possible to create your own custom model factories if the creation of the model class required specialized business logic. However in order to use the factory you had to specify it everytime you created a model class instance. Not only was this tedious and it required you to override some of the standard functionality in the framework in order to ensure that the correct model factory was used consistently, it was also error prone since everyone else had to know that to construct valid instances of the model class they had to use the specialized model factory.
This issue has now been rectified with the introduction of a global model factory service where you can register your factory and tie it to the model class type after which the framework will use the specialized factory instead of the default factory.
In order to register a specialized factory simply call the RegisterFactory method on application startup and all will be ready to go.
using ItemBinding.Model; using ItemBinding.Application; public class ItemBindingInitialization { public void RegisterFactories() { IModelFactory customModelFactory = new CustomModelFactory(); ModelFactoryService.RegisterModelFactory<CustomModel>(customModelFactory); } }
Once the factory has been registered all parts of the framework will use it automatically. However if you want to manually retrieve a previously registered factory you can do it with the ResolveModelFactory method of the model factory service.
IModelFactory customModelFactory = ModelFactoryService.ResolveModelFactory(typeof(CustomModel));
I hope this will prove useful to someone. Please stay tuned for more tips and tricks about the Sitecore Itembinding Framework.
The Sitecore Itembinding Framework is available through NuGet http://www.nuget.org/packages?q=itembinding
And to learn more about the framework check out the documentation on GitHub https://github.com/BoBreiting/SitecoreItemBinding