The json stuff is not related to DDD. you proably won't find anything
about json in that book. :)
The DDD concern is that Dictionary is a Value Object. You don't
create an Entity by extending a VO. Entities *encapsulate* Value
Objects. In RavenDB terms - the dictionary would go inside the
Document. The document isn't a dictionary itself. In OOP terms, the
relationship is "has a" instead of "is a".
Going back to the JSON issue. Say you wanted to extend a dictionary
and actually use it as a VO. So not adding an Id property, but some
other property like Name. Even then, you have issues.
Why? Because Dictionary<T,T> implements the ISerializable interface so
that the values being serialized are coming from the key/value pairs
of the dictionary. Json.Net honors that interface.
It wouldn't really make sense anyway. Say you had:
public class Foo : Dictionary<string,string>
{
public string Name { get; set; }
}
And then you had json of:
foo
{
"Name" : "fred",
"Bar" : "baz"
}
How would deserialization know where to put the name? In a normal
dictionary, both items would go into the key/value pairs. What
happens in this one? Does Name go in the property instead of the
dictionary? Does it go in both? Do I have to synchronize them
somehow? It just doesn't work.
Now, you certainly could add some properties that poked into the
dictionary directly:
public class Foo : Dictionary<string,string>
{
public string Name
{
get { return this["Name"]; }
set { this["Name"] = value; }
}
}
On Jan 11, 1:18 am, Georgios Diamantopoulos <
georgi...@live.com>