Giter Club home page Giter Club logo

Comments (5)

alkampfergit avatar alkampfergit commented on September 21, 2024

Actually we have in Jarvis aggregates with no default constructor, we have a factory that use default constructor or uses Castle.Windsor to resolve with optional external services.

We never have initialization in constructor with some properties that have business meaning. In your example you have a

public person(string name)

And we would never have such constructor in an aggregate, we will use the default aggregate and then call some method like SetName, or whatever. In such a situation some of the events should be raised in the constructor, and is a situation we do not want to handle. The constructor is there only to inject external dependencies and nothing related to business or something that should raise events.

The init is called by the repository, the situation we have is that no aggregate is created outside of the repository (except for testing).

You can always use a custom aggregate factory if you really need to use some special constructors.

Alk.

from nstore.

mauroservienti avatar mauroservienti commented on September 21, 2024

If I do something like this:

var p = new Person();
p.SetName("mauro");

where SetName is defined as:

public void SetName(string name)
{
   Emit(new NameChanged( name ));
}

and PersonState is as:

public class PersonState
{
   private void On(NameChanged @event){ ... }
}

A NRE is thrown, inspecting with the debugger the aggregate State protected property is null, looking at source code State is instantiated only when Init is called. Thus the question, do I need to manually call Init.

from nstore.

mauroservienti avatar mauroservienti commented on September 21, 2024

I think I understood, a call to Repository.GetByIdAsync<TAggregate> is mandatory, if the aggregate doesn't exist it'll be created and returned to the caller, initialized.

from nstore.

alkampfergit avatar alkampfergit commented on September 21, 2024

from nstore.

mauroservienti avatar mauroservienti commented on September 21, 2024

Thanks

from nstore.

Related Issues (20)

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.