// Init is used to initialize aggregate (store pointer to the derived type)
// and/or initialize it with provided events (execute all event handlers)
Init is used to initialize aggregate (store pointer to the derived type)
and/or initialize it with provided events (execute all event handlers)
// Init is used to initialize aggregate ( store pointer to the derived type ) // and / or initialize it with provided events ( execute all event handlers )
func (a *AggregateRoot) Init(aggrPtr interface{}, evts ...interface{}) error {
	a.aggrPtr = reflect.ValueOf(aggrPtr)
	if a.aggrPtr.Kind() != reflect.Ptr {
		return fmt.Errorf("aggrPtr needs to be a pointer")
	}
	var err error
	for _, evt := range evts {
		err = a.mutate(evt)
		if err != nil {
			return err
		}
		a.version++
	}
	return nil
}
func ( a * AggregateRoot ) Init ( aggrPtr interface { } , evts ... interface { } ) error { a . aggrPtr = reflect . ValueOf ( aggrPtr ) if a . aggrPtr . Kind ( ) != reflect . Ptr { return fmt . Errorf ( " " ) } var err error for _ , evt := range evts { err = a . mutate ( evt ) if err != nil { return err } a . version ++ } return nil }
Init is used to initialize aggregate (store pointer to the derived type)
and/or initialize it with provided events (execute all event handlers)
Init is used to initialize aggregate ( store pointer to the derived type ) and / or initialize it with provided events ( execute all event handlers )