Giter Site home page Giter Site logo

boase / be.cqrs Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 2.0 396 KB

Production implementation of the common domain object repository pattern in a CQRS context

License: MIT License

C# 100.00%
asp-net aspnetcore cqrs cqrs-framework dotnet dotnet-core

be.cqrs's People

Contributors

alexzeitler avatar boase avatar cypressious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

be.cqrs's Issues

Direct Denormalizer Call After Save

Create a possibility to run the denormalizers in a way so that they are called right after saving the event. This way the usage of a messagebus cam be omitted.

This will then make it required to have a simple possibility to run the creation of the read database

"Type" property in log causes conflict with Logstash

Description

When inserting events into the repository, the generated logs use the a Type property:
MongoCommitRepository
Line 194
logger.LogError(e, "Error when saving a commit for {type} {id}", commit.AggregateType, commit.AggregateId);
and Line 203
logger.LogDebug("{Count} events for {Type} - {Id} handled. Result: {Result}.", commit.Events.Count, commit.AggregateType, commit.AggregateId, result.CommitId);

When using structured logs, the Type property is usually already in use by some data processing pipelines, in this particular Logstash, which then can cause errors.

Proposal

Rename the Type property to AggregateType to prevent such conflicts

Issues when duplicate domain object assembly calls

  new EventSourceConfiguration()
          .SetDomainObjectAssemblies(typeof(RealmDomainObject).Assembly)
          .SetDomainObjectAssemblies(typeof(LocalizationDomainObject).Assembly) // <= duplicate assembly
          .SetServiceProviderActivator()

Allow moving/renaming Domain Object

Currently, the full name of the domain object including namespace is persisted. Allow moving or renaming the domain object while keeping backward compatibility, e.g. by providing a mapping from old full name to new full name, either in the configuration or in an attribute.

Allow to pass serilog enricher for serilog logging config

This would allow to e.g. implement a Enricher (outside BE.CQRS) which handles correlation id and passing the Enricher to the config, the correlation id would also be used in BE.CQRS, thus it wouldn't be a black box correlation logging wise.

Fix broken DomainObjectTests

[xUnit.net 00:00:01.1304280]     BE.CQRS.Domain.Tests.DomainObjectTests.Visiting.WhenVisiting.ItProcessedAppliedAndUncommittedEvents [FAIL]
[xUnit.net 00:00:01.1365290]     BE.CQRS.Domain.Tests.ConventionEventhandlerTests.WhenEventIsRaised.ItCallsTheMethod [FAIL]
Failed   BE.CQRS.Domain.Tests.DomainObjectTests.Visiting.WhenVisiting.ItProcessedAppliedAndUncommittedEvents
Error Message:
 System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
   at BE.CQRS.Domain.DomainObjects.DomainObjectBase.StateInternal[T](Boolean excludeUncommitted) in /Users/alexzeitler/src/github.com/BE.CQRS/src/Domain/Domain/DomainObjects/DomainObjectBase.cs:line 195
   at BE.CQRS.Domain.DomainObjects.DomainObjectBase.State[T]() in /Users/alexzeitler/src/github.com/BE.CQRS/src/Domain/Domain/DomainObjects/DomainObjectBase.cs:line 185
   at BE.CQRS.Domain.Tests.DomainObjectTests.Visiting.WhenVisiting..ctor() in /Users/alexzeitler/src/github.com/BE.CQRS/src/Domain/Domain.Tests/DomainObjectTests/Visiting/WhenVisiting.cs:line 26
Failed   BE.CQRS.Domain.Tests.ConventionEventhandlerTests.WhenEventIsRaised.ItCallsTheMethod
Error Message:
 System.ArgumentNullException : Value cannot be null.
Parameter name: logger
Stack Trace:
   at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
   at Microsoft.Extensions.Logging.LoggerExtensions.LogTrace(ILogger logger, String message, Object[] args)

Commit IDs are empty string

Issue appears repeatedly and with no recognisable pattern so far. The stacktrace is the following:

[11:14:09 ERR] Error handling command "Csi.Identities.Commands.AddPhoneCommand" - '' is not a valid 24 digit hex string.
System.FormatException: '' is not a valid 24 digit hex string.
   at MongoDB.Bson.ObjectId.Parse(String s)
   at MongoDB.Bson.BsonTypeMapper.Convert(Object value, Conversion conversion)
   at MongoDB.Bson.BsonTypeMapper.MapToBsonValue(Object value, BsonType bsonType)
   at MongoDB.Bson.BsonObjectId.Create(Object value)
   at BE.CQRS.Data.MongoDb.Commits.MongoCommitRepository.ByInternalId(String commitId)
   at BE.CQRS.Data.MongoDb.MongoDomainObjectRepository.ByAppendResult(AppendResult result)
   at BE.CQRS.Domain.DomainObjectRepositoryBase.SaveAsync[T](T domainObject, Boolean preventVersionCheck)
   at BE.CQRS.Domain.Conventions.ConventionCommandInvoker.InvokeAndSaveInternalAsync(Type domainObjectType, ICommand cmd, IEnumerable`1 commands)
   at BE.CQRS.Domain.Conventions.ConventionCommandInvoker.InvokeAndSaveAsync(Type domainObjectType, ICommand cmd, IEnumerable`1 commandMapping)
   at BE.CQRS.Domain.Commands.InMemoryCommandBus.HandleCommand(ICommand cmd)

Support Logging Infrastructure

It should be possible to optin into logging messages i.g. to print them to the console

Idea:

  • Support a common LoggingInterface
  • Provide da Default Console implementation
  • Create Extension Methods for simple bootstrapping

Di / DataContext Classes

to improve dependencies it would be helpfull to have Di-/ Data - Context Classes which can be recieved from the service provider.

this would also reduce the size of the ctor and so son

image

No Exceptions logged in Denormalizer Repository

Given this Customer class:

 public sealed class Customer
    {
        [BsonId]
        public ObjectId Id { get; set; }
        public string Name { get; set; }
    }

And this Repository:

    {
        private readonly IDenormalizerContext context;

        public CustomerRepository(IDenormalizerContext context) : base(context.Db, "Customer")
        {
            this.context = context;
        }

        public Task AddCustomer(string customerId)
        {
            var dto = new Customer
            {
                Id = new ObjectId(customerId)
            };

            return Collection.InsertOneAsync(dto);
        }
    }

When debbuging in Rider, I get this exception:

System.FormatException: String should contain only hexadecimal digits.   at MongoDB.Bson.BsonUtils.ParseHexString(String s)   at MongoDB.Bson.ObjectId..ctor(String value)   at AspNetCoreSample.Denormalizer.Repositories.CustomerRepository.AddCustomer(String customerId) in /home/alexzeitler/src/github.com/BE.CQRS-15/Samples/3_ASPNET_Core_ReadModels/AspNetCoreSample.Denormalizer/Repositories/CustomerRepository.cs:line 18   at AspNetCoreSample.Denormalizer.CustomerDenormalizer.On(CustomerCreatedFromApiEvent event) in /home/alexzeitler/src/github.com/BE.CQRS-15/Samples/3_ASPNET_Core_ReadModels/AspNetCoreSample.Denormalizer/CustomerDenormalizer.cs:line 26

But the application does not log any errors on console.

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.