com.scalified.axonframework.cdi.CdiSetup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of axonframework-cdi Show documentation
Show all versions of axonframework-cdi Show documentation
AxonFramework CDI Integration Library
/*
* Copyright 2019 Scalified
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalified.axonframework.cdi;
import com.scalified.axonframework.cdi.commons.CdiUtils;
import com.scalified.axonframework.cdi.commons.ReflectionUtils;
import com.scalified.axonframework.cdi.configuration.LazyRepository;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.config.Configuration;
import org.axonframework.modelling.command.Aggregate;
import org.axonframework.modelling.command.Repository;
import org.axonframework.queryhandling.QueryGateway;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
import java.lang.reflect.Type;
/**
* Configuration class containing Axon components bean producers
*
* @author shell
* @since 2019-04-12
*/
@ApplicationScoped
public class CdiSetup {
/**
* Produces Axon {@link Configuration} {@link ApplicationScoped} bean
*
* @param extension extension to use
* @return Axon {@link Configuration} {@link ApplicationScoped} bean
*/
@Produces
@ApplicationScoped
Configuration configuration(CdiExtension extension) {
return extension.getConfiguration();
}
/**
* Produces Axon {@link CommandGateway} {@link ApplicationScoped} bean
*
* @param configuration Axon {@link Configuration}
* @return Axon {@link CommandGateway} {@link ApplicationScoped} bean
*/
@Produces
@ApplicationScoped
CommandGateway commandGateway(Configuration configuration) {
return configuration.commandGateway();
}
/**
* Produces Axon {@link QueryGateway} {@link ApplicationScoped} bean
*
* @param configuration Axon {@link Configuration}
* @return Axon {@link QueryGateway} {@link ApplicationScoped} bean
*/
@Produces
@ApplicationScoped
QueryGateway queryGateway(Configuration configuration) {
return configuration.queryGateway();
}
/**
* Produces Axon {@link Repository} {@link Dependent} bean
*
* @param point point to use
* @param beanManager current {@link BeanManager}
* @param type of {@link Aggregate}
* @return Axon {@link Repository} {@link Dependent} bean
*/
@Produces
Repository repository(InjectionPoint point, BeanManager beanManager) {
Type aggregateType = ReflectionUtils.getTypeArgument(point.getType(), Repository.class);
return new LazyRepository<>(() -> {
Configuration configuration = CdiUtils.getReference(beanManager, Configuration.class);
return configuration.repository(ReflectionUtils.getRawType(aggregateType));
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy