DDD Domain driven Design: a domain infrastructure layer

Source: Internet
Author: User
Tags abstract bool static class tostring

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)); }
    }
     
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.