Code Monkey home page Code Monkey logo

powerumc.aspnetcore.core's Introduction

Powerumc.AspNetCore.Core

Easyily build up ours Micro Services Architecture(MSA) and Domain Driven Development(DDD).

Micro services architecture

RegisterAttribute

public interface ITestService
{
    Task<List<string>> GetStringsAsync();
}

[Register(typeof(ITestService))] // Regist components
public class TestService : ITestService
{
    public async Task<List<string>> GetStringsAsync()
    {
        return await Task.FromResult(new List<string>()
        {
            "Junil Um",
            "Hanji Jung"
        });
    }
}

Domain Driven Development

Implements ValueObject

public class Author : ValueObject
{
    public string Title { get; }
    public string Url { get; }

    public Author(string title, string url)
    {
        Title = title;
        Url = url;
    }
}

Implements DomainEvent

public class RssFeedCreateDomainEvent : DomainEvent
{
    public Author Author { get; }

    public RssFeedCreateDomainEvent(Author author)
    {
        this.Author = author;
    }
}

Implements DomainEventHandler

public class RssFeedCreateDomainEventHandler : IDomainEventHandler<RssFeedCreateDomainEvent>
{
    private readonly TraceId _traceId;
    private readonly ILogger<RssFeedCreateDomainEventHandler> _logger;
    private readonly IRssFeedsRepository _rssFeedsRepository;

    public RssFeedCreateDomainEventHandler(TraceId traceId,
        ILogger<RssFeedCreateDomainEventHandler> logger,
        IRssFeedsRepository rssFeedsRepository)
    {
        _traceId = traceId;
        _logger = logger;
        _rssFeedsRepository = rssFeedsRepository;
    }

    public async Task Handle(RssFeedCreateDomainEvent @event)
    {
        _logger.Log(_traceId, @event.ToJson());

        await _rssFeedsRepository.CreateAsync(new RssFeed
        {
            Title = @event.Author.Title,
            Url = @event.Author.Url,
            CreateDate = DateTime.UtcNow,
            ModifyDate = DateTime.UtcNow
        });
    }
}

Publishing EventBus

public interface IRssFeedsService
{
    Task CreateAsync(RssFeedCreateRequest request);
}

[Register(typeof(IRssFeedsService))]
public class RssFeedsService : IRssFeedsService
{
    private readonly TraceId _traceId;
    private readonly ILogger<RssFeedsService> _logger;
    private readonly IEventBus _eventBus;

    public RssFeedsService(TraceId traceId,
        ILogger<RssFeedsService> logger,
        IRssFeedsRepository repository,
        IEventBus eventBus)
    {
        _traceId = traceId;
        _logger = logger;
        _repository = repository;
        _eventBus = eventBus;
    }

    public async Task CreateAsync(Domain.Requests.V1.RssFeedCreateRequest request)
    {
        _logger.Log(_traceId, request.ToJson());
        
        _eventBus.Publish(new RssFeedCreateDomainEvent(new Author(request.Title, request.Url)));

        await Task.CompletedTask;
    }
}

See also

powerumc.aspnetcore.core's People

Contributors

powerumc avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.