|
| 1 | +/* |
| 2 | + * Copyright (c) 2010-2020. Axon Framework |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.axonframework.extensions.kotlin |
| 18 | + |
| 19 | +import org.axonframework.messaging.MetaData |
| 20 | +import org.axonframework.modelling.command.Aggregate |
| 21 | +import org.axonframework.modelling.command.AggregateLifecycle |
| 22 | +import org.axonframework.modelling.command.ApplyMore |
| 23 | + |
| 24 | +/** |
| 25 | + * Alias for [AggregateLifecycle.apply] method. |
| 26 | + * @param payload payload of the event message to be applied. |
| 27 | + * @return fluent instance to apply more. |
| 28 | + */ |
| 29 | +fun applyEvent(payload: Any): ApplyMore = AggregateLifecycle.apply(payload) |
| 30 | + |
| 31 | +/** |
| 32 | + * Alias for [AggregateLifecycle.apply] method. |
| 33 | + * @param payload payload of the event message to be applied. |
| 34 | + * @param metaData metadata to be included into the event message. |
| 35 | + * @return fluent instance to apply more. |
| 36 | + */ |
| 37 | +fun applyEvent(payload: Any, metaData: MetaData): ApplyMore = AggregateLifecycle.apply(payload, metaData) |
| 38 | + |
| 39 | +/** |
| 40 | + * Create new aggregate instance. |
| 41 | + * @param [T] aggregate type. |
| 42 | + * @param factoryMethod factory method. |
| 43 | + */ |
| 44 | +inline fun <reified T : Any> createNew(noinline factoryMethod: () -> T): Aggregate<T> = AggregateLifecycle.createNew(T::class.java, factoryMethod) |
0 commit comments