Evento Framework
  • Introduction
  • Architecture Overview
    • Distributed Systems & Microservices
    • Recative Manifesto & Reactive Principles
    • State-of-the-art Patterns
      • DDD (Domain Driven Design)
      • CQRS (Command Query Responsability Separation)
      • Event Sourcing
      • Messaging
      • Saga
  • GETTING STARTED
    • Quick Start
    • TodoList - RECQ Tutorial
      • Problem Description and Requirement Gathering
      • RECQ Payload Design
      • RECQ Components Design
      • Set up your Development Environment
      • RECQ Payload Evento Implementation
        • Domain Commands
        • Domain Events
        • Views
        • Queries
      • RECQ Components Evento Implementation with Spring Data
        • TodoListAggregate
        • TodoList Model with Spring Data
        • TodoListProjector
        • TodoListProjection
        • TodoList Invoker
      • Expose the RECQ architecture with Spring Web
      • Test Your App
    • Extend TodoList - Handle Complexity Tutorial
      • Unique identifier generation
      • Extends behaviors with Observer and Services
      • Cross Domain Consistency with Sagas
      • Handle Real time data updates with MQTT and Save-Notify Pattern
  • RECQ Patterns
    • RECQ Patterns
    • RECQ System Pattern
      • Component
      • Message Gateway
      • System State Store
    • RECQ Communication Pattern
      • Component to Component
      • Component to System State Store
      • System State Store to Component
    • RECQ Component Pattern
      • Aggregate
      • Projector
      • Projection
      • Service
      • Invoker
      • Saga
      • Observer
  • Evento Framework
    • Evento Framework Introcution
    • Payload and Messages
      • Command
        • Domain Command
        • Service Command
      • Event
        • Domain and Service Event
      • Query and View
    • @Component
      • @Aggregate
        • Aggregate State
        • @AggregateCommandHandler
        • @EventSourcingHandler
      • @Projector
        • Projector @EventHandler
      • @Projection
        • @QueryHandler
      • @Service
        • @CommandHandler
      • @Invoker
      • @Saga
        • SagaState
        • @SagaEventHandler
      • @Observer
    • Dead Event Queues
    • EventoBundle
      • EventoServerMessageBusConfiguration
      • ConsumerStateStore
        • InMemoryConsumerStateStore
        • PostgresConsumerStateStore
        • MysqlConsumerStateStore
      • Context
      • TracingAgend and @Track
        • SentryTracingAgent
      • Autoscaling Protocol
        • ThreadCountAutoscalingProtocol
      • Injector and @Component
  • Evento Server
    • Evento Server Introduction
    • SetUp Evento Server
      • Advanced Options
      • Evento Event Store Modes: APES and CPES
    • Evento Server Cluster
    • Bundle Deploy Script
  • EVENTO GUI
    • Explore RECQ Systems Visually
    • GUI Auth
    • Payload Catalog
    • Component Catalog
    • Bundle Catalog
    • Cluster Status (Experimental)
    • Flows
      • Performance Evaluation
    • Application Graph
    • System State Store
  • Evento CLI
    • Evento CLI Introduction
    • Update Version
    • Publish
Powered by GitBook
On this page
  1. Evento Framework
  2. EventoBundle

Injector and @Component

Simplifying Component Management

In the realm of complex applications built with modular components, managing dependencies between them can quickly become a tangled mess. This is where Dependency Injection (DI) shines, promoting loose coupling and fostering code maintainability. The Evento framework embraces DI principles, offering a streamlined approach to handling component lifecycles and dependency resolution.

Introducing the Injector: The Dependency Resolver

The Injector interface serves as the heart of Evento's DI system. It acts as a powerful function that takes a class as input and returns a corresponding instance. This instance will have all its required dependencies fulfilled through the injector's magic.

Behind the Scenes:

  • When Evento encounters a class marked with @Component or its derivatives, the framework utilizes the configured injector to create an instance. This instance is managed internally by Evento and is not directly exposed for injection into other components.

  • The injector examines the component's constructor, identifying any dependencies declared as parameters.

  • The injector then recursively retrieves these dependencies using itself, ensuring a chain reaction of dependency resolution.

Spring Integration Example:

The provided code snippet showcases how Evento integrates with Spring Boot's dependency injection:

@Projector(version = 3)
public class DemoProjector {

  private final DemoRepository demoRepository;

  public DemoProjector(DemoRepository demoRepository) {
    this.demoRepository = demoRepository;
  }

  // ...
}

In this example, DemoProjector is a component requiring a DemoRepository instance. During bundle creation:

EventoBundle.Builder.builder()
  .setBasePackage(DemoQueryApplication.class.getPackage())
  .setConsumerStateStoreBuilder(InMemoryConsumerStateStore::new)
  .setInjector(factory::getBean) // Spring's getBean function as injector
  .setBundleId(bundleId)
  // 

We configure the setInjector method with factory::getBean. This essentially tells Evento to leverage Spring's getBean function to resolve dependencies for the components Evento manages internally. When DemoProjector is instantiated, the injector (Spring's getBean in this case) will locate and provide the required DemoRepository instance.

Benefits of Evento's DI:

  • Simplified Component Management: Evento handles component lifecycles, reducing boilerplate code.

  • Improved Code Maintainability: Loose coupling through constructor injection promotes testability and modularity.

  • Flexibility: Supports various injector implementations for integration with different frameworks.

In Conclusion:

Evento's DI approach, with its @Component annotations and the powerful Injector interface, streamlines the process of creating and managing internal components. By leveraging existing frameworks like Spring, Evento simplifies dependency resolution within your application. Remember, the chosen injector depends on your framework or custom implementation.

PreviousThreadCountAutoscalingProtocolNextEvento Server Introduction

Last updated 12 months ago