One of the great features of the Spark view engine is it's modular design. This modularity give you great control over how the view engine functions and allows you to create custom implementations of just about any component that the ViewEngine depends on. You can even override the view engine itself.
The reason this is possible is because Spark has it's own embedded service locator which it uses to resolve key dependencies which Spark relies on.
In my last article on creating a custom bindings provider I took advantage of this feature to inject my own bindings provider.
Looking at the code
// Register Spark var services = SparkEngineStarter.CreateContainer(); services.SetService<IBindingProvider>(new CustomBindingProvider()); SparkEngineStarter.RegisterViewEngine(services);
You can see that the first line is the line that actually instantiates the Spark IoC container.
The second line registers my CustomBindingProvider with the IoC container and finally I instantiate the View Engine with the container which now has my custom service loaded.
Digging through the Spark source shows that the following are just some of the services you can inject using the Spark Service Locator:
- ICompiledViewHolder IViewFolder
- IBindingProvider ITemplateLocator
These modules combined with the Spark service locator give you a lot of power and flexibility when it comes to extending the capabilities of the base view engine so your view engine is working harder for you.