Git Product home page Git Product logo

basic_ioccontainer's Introduction

Basic IoC Container Implementation

Note: This IoC container implementation is for educational purposes and not designed for practical usage in production applications. It does not handle circular dependencies.

This is a basic implementation of an IoC (Inversion of Control) container in Java. The primary purpose of this project is to help you understand the fundamental concepts of IoC containers, dependency injection, and how they work in Java.

Features

  1. Component Scanning: The container can scan and discover classes annotated with @Component in your project.

  2. Dependency Injection: It supports constructor-based dependency injection for the discovered components.

  3. Annotations: You can use @Autowired for field injection and @Qualifier to specify which implementation to use when multiple implementations are available.

  4. Singleton Scope: Components are created in the singleton scope by default. This means that the container maintains a single instance of each component.

  5. Default Implementation: You can use the @Default annotation to specify the default implementation for an interface if there are multiple implementations. To specify the interfaces that a class should be the default implementation for, use the @Default annotation with an array of interface classes.

  6. Prototype Scope: You can mark components with the @Prototype annotation to create a new instance each time it is requested.

    • Qualifier and Name-Based Injection: Fields are injected by name. If a field is not annotated with @Qualifier, the container will prioritize matching by field name. If no qualifier and no matching field name are found, the default implementation is used.

Limitations

  • This is a basic and minimalistic IoC container and is not intended for production use. It lacks many features and optimizations found in more mature IoC containers like Spring.

  • Error handling and advanced features like aspect-oriented programming, custom scopes, and circular dependency handling are not implemented.

    Feel Free to Experiment

i encourage you to experiment and learn with this IoC container. Explore the source code, make modifications, and leave a star if u can.

Usage

  1. Create an instance of the Container class and call the getService method to retrieve your components.

  2. The container handles dependency resolution and creates instances of your components as needed.

  3. Add the @Component annotation to your classes to mark them as components to be managed by the IoC container.

  4. Use @Default to specify default implementations for interfaces.

Example:

@Component
@Default({MyInterface1.class, MyInterface2.class})
public class MyComponent implements MyInterface1, MyInterface2 {
    // ...
}


basic_ioccontainer's People

Contributors

mountassirjerrari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.