-
Notifications
You must be signed in to change notification settings - Fork 2
Using Custom Serializers
TINA-ORM uses serialization to store objects automagically, without any pesky schemas or explicit mapping.
By default, Tina uses the JavaScriptSerializer
class from the System.Web.Script.Serialization
namespace. Even so, you may not want to use the default. Maybe you prefer a faster serializer or you want to serialize to a different format. If, for any reason, you want to plug in a different serializer, Tina offers an easy solution - ISerializer
.
TinaORM.Core
defines the ISerializer
interface which offers two simple methods (namely Serialize
and Desirealize<T>
). You plug in a class that implements the interface and serialize away. You might recognize it as Ye Olde Adapter Pattern.
Tina comes with a few built in serializer packages (For ServiceStack.Text and JSON.NET) and plans for other built in formats (YAML, BSON, MessagePack and more!)
As mentioned in the quickstart guide, Tina uses configuration objects to connect to different databases. It also uses them to define custom serializers. Here, watch.
string connectionString = "Data Source=...";
// Fluent version
Tina tina = Tina.ConnectsTo<MsSql>(connectionString, new ServiceStackTextSerializer());
// new expression version
TinaConfig config = new MsSql(connectionString, new ServiceStackTextSerializer());
Tina tina2 = new Tina(config);
Speaking of extensibility, how about writing your own data adapter?