In Litium 7, a new API is introduced for the Websites area. This is in addition to Products, Customers and Media, for which it has been introduced in previous versions. Sales will be upgraded in future versions.
The API is structured into different assemblies to separate the domain entities and service contracts from the application logic. When you extend and build customer specific functionality, you only need to include references to the assemblies that contain domain entities and service contracts. This way there will be a minimal number of external dependencies.
A service contract can be either the domain service that will handle the entity or an extension point. Domain services have an abstract class as a contract and extension points have interfaces as contracts.
Domain entities and service contracts that have breaking changes, except classes and interfaces in the Internal namespace, will be announced in the release notes for each release. Classes and interfaces in the Internal namespace should not be used in customer solutions and can be removed by Litium without prior notice.
Naming of the assemblies that contain the domain entities or service contracts:
- Litium.Abstractions - contains core domain entities and service contracts.
- Litium.Web.Abstractions - contains domain entities and service contracts for web applications.
- Litium.Web.Mvc.Abstractions - contains domain entities and service contracts for ASP.NET MVC applications.
- Litium.Web.WebApi.Abstractions - contains domain entities and service contracts for ASP.NET WebAPI applications.
- Litium.Web.Administration.Abstractions – contains domain entities and service contracts for extending the administration interface.
The namespace in the assembly is the same as the assembly name without “Abstractions”.
Litium.Common.KeyLookupService can be used for high performance lookup between Id and SystemId of entities. When a value is requested it is cached for future calls making it possible to lookup SystemId for an Id and vice versa.
Example getting SystemId for currency from Id:
_keyLookupService.TryGetId<Currency>(entity.CurrencySystemId, out id)
Litium.Common.SettingService is a simple key-value storage that can be used to store serializable objects in the database.
var lastSyncDate = _settingService.Get<DateTimeOffset>(key);
// Sync stuff...
_settingService.Set(key, DateTimeOffset.Now);
Applications can be designed through
- static instance that contains the services and caches
- dependency injection that holds the state of the services and inject the dependency (constructor parameters) for the service into the instance.
The services in the API are designed to use dependency injection wherever possible. When using dependency injection, services can easily be extended or replaced. Services are used to create/read/update/delete the entity.
How to find the correct service
If the entity name is "Entity" the service name is "EntityService".
Example:
- entity = BaseProduct
- service = BaseProductService
The service exists in the same namespace as the entity.
All entities that implement Litium.ComponentModel.IReadOnly can be in read-only mode to prohibit that the entity is changed. To change an entity that is read-only, you need to invoke the method MakeWritableClone to create a clone of the object that can be changed.
Litium strongly advises against changing the data directly in the database. If you choose to do so anyway:
- you are responsible to ensure business rules are met
- you are responsible to ensure that correct events are fired
- you are responsible to ensure that search indexes are updated.
Complete references to the current and previous versions of the Litium API can be found here.