Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BLZT-47] Added md files for Configuration #108

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions features/Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ It initializes the list with default post-processors such as the ScheduleBeanPos
- [Setter](core/Setter.md)
- [Field](core/Field.md)
- [Collections](core/Collections.md)
- Prototype Bean
- Singleton Bean
- [Prototype Bean](core/Prototype.md)
- [Singleton Bean](core/Singleton.md)


- Configuration support
- Annotation configuration `@Component`, `@Service`.
- Annotation `@Autowired`
- Java Configuration `@Bean`, `@Configuration`.
- [Annotation configuration](core/Component.md) `@Component`, `@Service`.
- [Annotation](core/Autowired.md) `@Autowired`
- [Java Configuration](core/Configuration.md) `@Bean`, `@Configuration`.


- Annotations
Expand Down
56 changes: 56 additions & 0 deletions features/core/Autowired.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Autowired Annotation

## Introduction

The `Autowired` annotation in Bring is a powerful mechanism for automatically injecting dependencies.
It can be applied to fields, constructors, and methods. Below are examples demonstrating its usage in various scenarios.

## Example 1: Field Injection

```java
@Component
public class UserService {

@Autowired
private UserRepository userRepository;

// Other methods and properties
}
```
In this example, the UserRepository is automatically injected into UserService.

## Example 2: Constructor Injection

```java
@Service
public class OrderService {

private final ProductService productService;

@Autowired
public OrderService(ProductService productService) {
this.productService = productService;
}

// Other methods and properties
}
```
Here, the ProductService dependency is injected via constructor injection.

## Example 3: Method Injection

```java
@Component
public class A {

private C c;

@Autowired
public void setC(C c) {
this.c = c;
}

// Other methods and properties
}
```
Here, the C dependency is injected via setter method.
52 changes: 52 additions & 0 deletions features/core/Component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Component and Service Annotations

## Component Annotation

The `@Component` annotation in Bring indicates that an annotated class is a Bring component. This annotation serves as a marker for Bring to automatically detect and register the annotated class as a bean during component scanning.

By default, the name of the bean will be the simple name of the annotated class. You can customize the bean name by providing a value to the `value` attribute. If no value is provided, the bean name will be generated based on the class name with the initial letter in lowercase.

This annotation is part of the Bring Framework's component scanning mechanism, which allows for automatic discovery and registration of Bring beans.

### Usage Example:

```java
@Component
public class MyComponent {
// Class definition
}

// Custom bean name
@Component("customBeanName")
public class AnotherComponent {
// Class definition
}
```
In the above example, `MyComponent` and `AnotherComponent` are annotated with `@Component`.
This allows Bring to automatically detect and register these classes as beans during component scanning.

## Service Annotation

The `@Service` annotation in Bring is also used to indicate that an annotated class is a Bring component.
It serves the same purpose as the `@Component` annotation, providing a marker for Bring to automatically
detect and register the annotated class as a bean during component scanning.

Similarly, you can customize the bean name using the value attribute.

### Usage Example:

```java
@Service
public class MyComponent {
// Class definition
}

// Custom bean name
@Service("customBeanName")
public class AnotherComponent {
// Class definition
}
```

In this example, `MyComponent` and `AnotherComponent` are annotated with `@Service`.
This annotation is often used for classes that define business services or service components.
37 changes: 37 additions & 0 deletions features/core/Configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Configuration Annotation

## Introduction

The `Configuration` annotation in Bring is used to indicate that a class is a source of bean definitions.
Bean definitions declared within a configuration class are registered during the invocation of
`BeanFactoryPostProcessors`. The dedicated factory post processor for configuration classes is
`ConfigurationClassPostProcessor`.

Beans inside a configuration class are created by adding methods and annotating them with
the `@Bean` annotation. Configuration beans must be of Singleton scope and are registered before the
beans defined inside them.

The `@Configuration` annotation in Bring plays a crucial role in declaring bean definitions and configuring the application context.
It allows developers to define and organize beans in a modular and maintainable way.

## Usage Example

```java
@Configuration
public class MyConfiguration {
// Bean definitions using @Bean annotations

@Bean
public MyBean myBean() {
return new MyBean();
}

@Bean
public AnotherBean anotherBean() {
return new AnotherBean();
}
}
```
In this example, `MyConfiguration` is a configuration class annotated with `@Configuration`.
It declares two beans (myBean and anotherBean) using methods annotated with `@Bean`.
These beans will be registered with the Bring context during the application context initialization.
44 changes: 44 additions & 0 deletions features/core/Prototype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Prototype Bean Scope

## Introduction

In Bring Framework, a prototype-scoped bean is a bean for which a new instance is created every time it is requested.
To declare a prototype-scoped bean, you can use the `@Scope` annotation with name property `BeanScope.PROTOTYPE`
and a proxyMode. The proxyMode is turned off by default (`ProxyMode.OFF`), but it can be turned on (`ProxyMode.ON`)
in case a proxy is needed. For example when injecting a Prototype bean into a Singleton one.

## BeanScope Enumeration

The `BeanScope` enumeration represents the scope of beans in an application. It includes two values:

- **SINGLETON:** Indicates that a single instance of the bean is created and shared throughout the application context.
- **PROTOTYPE:** Indicates that a new instance of the bean is created whenever it is requested.

### Example Usage:

```java
@Scope(name = BeanScope.PROTOTYPE)
public class MyPrototypeBean {
// Bean definition and methods
}
```

## ProxyMode Enumeration

The ProxyMode enumeration represents the modes of proxy functionality. It includes two values:

- **OFF:** Indicates that the proxy mode is turned off.
- **ON:** Indicates that the proxy mode is turned on.

### Example Usage:

```java
@Scope(name = BeanScope.PROTOTYPE, proxyMode = ProxyMode.ON)
public class MyPrototypeBeanWithProxy {
// Bean definition and methods
}
```

In the above example, `ProxyMode.ON` indicates that the proxy mode is turned on for the prototype-scoped bean.
By combining the `@Scope` annotation with `ProxyMode`, you can define prototype-scoped beans, ensuring that a
new instance is created whenever the bean is requested.
28 changes: 28 additions & 0 deletions features/core/Singleton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Singleton Bean Scope

## Introduction

In Bring Framework, a singleton-scoped bean is a bean for which a single instance is created and shared throughout
the application context. To declare a singleton-scoped bean, you can use the `@Scope` annotation with name property
`BeanScope.SINGLETON` or without setting the name property in the annotation as Singleton is the default bean scope.

## BeanScope Enumeration

The `BeanScope` enumeration represents the scope of beans in an application. It includes two values:

- **SINGLETON:** Indicates that a single instance of the bean is created and shared throughout the application context.
- **PROTOTYPE:** Indicates that a new instance of the bean is created whenever it is requested.

### Example Usage:

```java
@Scope(name = BeanScope.SINGLETON)
public class MySingletonBean {
// Bean definition and methods
}

@Scope
public class MySingletonBean {
// Bean definition and methods
}
```