In fact, the infrastructure layer here is just some interface and base class of the domain layer, there are no other code such as day tools, just to illustrate some basic problems of the domain layer
1, the domain event simple implementation code, all comes to the asp.net design pattern book code
Namespace DDD. Infrastructure.Domain.Events
{public
interface idomainevent
{
}
}
Namespace DDD. Infrastructure.Domain.Events
{public
interface idomaineventhandler<t>: Idomaineventhandler
where t:idomainevent
{
void Handle (T e);
}
Public interface Idomaineventhandler
{
}
}
Namespace DDD. Infrastructure.Domain.Events
{public
interface idomaineventhandlerfactory
{
ienumerable< Idomaineventhandler<t>> getdomaineventhandlersfor<t> (T domainevent)
where t:idomainevent;
}
}
Namespace DDD. Infrastructure.Domain.Events
{public
class Structuremapdomaineventhandlerfactory: Idomaineventhandlerfactory
{public
ienumerable<idomaineventhandler<t>> Getdomaineventhandlersfor<t>
(T domainevent) where t:idomainevent
{
return Objectfactory.getallinstances<idomaineventhandler<t>> ();}}
Namespace DDD. Infrastructure.Domain.Events
{public
static class domainevents
{public
static Idomaineventhandlerfactory domaineventhandlerfactory {get; set;}
public static void Raise<t> (T domainevent) where t:idomainevent
{
var handlers = Domaineventhandlerfact Ory. Getdomaineventhandlersfor (domainevent);
foreach (var item in handlers)
{
item. Handle (domainevent);}}}
2, the domain layer interface code, many are to the MS Nlayer codes and Google code
Namespace DDD. Infrastructure.domain
{public
interface Ientity<out tid>
{
TId Id {get;}
}}
Namespace DDD. Infrastructure.domain
{public
interface iaggregateroot:iaggregateroot<string>
{
}
Public interface Iaggregateroot<out tid>: ientity<tid>
{
}
}
Namespace DDD. Infrastructure.domain {public abstract class Entitybase:entitybase<string> {protected entitybase (): This (null) {} protected entitybase (string id) {this.
id = ID; public override string Id {get {return base.
Id; } set {base.
Id = value; if (string. IsNullOrEmpty (this. ID) {this.
Id = Entitybase.newid (); }} public static string NewId () {return Guid.NewGuid ().
ToString ("N");
} public abstract class Entitybase<tid>: ientity<tid> {public virtual TId Id
{get;
Set
Public virtual ienumerable<businessrule> Validate () { return new businessrule[] {}; override bool Equals (object entity) {return entity!= null
;& entity is entitybase<tid> && this = = (entitybase<tid>) entity; Override int GetHashCode () {return this.
Id.gethashcode ();
public static BOOL operator = = (entitybase<tid> entity1, entitybase<tid> entity2) {
if ((object) entity1 = = null && (object) Entity2 = = null) {return true; } if ((object) Entity1 = = NULL | |
(object) Entity2 = = null) {return false; } if (entity1. id.tostring () = = Entity2.
Id.tostring ()) {return true;
return false; public static bool operator!= (Entitybase<tiD> entity1, entitybase<tid> entity2) {return (!) (
Entity1 = = Entity2)); }
}
}