nampython / temp

Create my own IoC / Dependency Container

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Amazing Project - Feel free to learn!

Report a Bug · Request a Feature . Ask a Question

IoC Container

Have you ever wondered how Spring core famework works. I've always been curious how it works, so I created this project. It mainly used Java Rejection and support most annotations like @Service, @Autowire, @Bean, @PostConstructor…

Table of Contents

General Information

//TODO

Prerequisites

Installation

You can run this project by 2 ways:

  • The simple way is to run command: mvn clean install. Your dependency is in m2\repository\

mvn clean install

In the file pom of your project and add in tag

<dependency>
 <groupId>org.example</groupId>
 <artifactId>ioc</artifactId>
 <version>1.0</version>
</dependency>
  • The other way is to run mvn package and get the generated jar file. Add this dependency in your project

mvn package

<dependency>
 <groupId>org.example</groupId>
 <artifactId>ioc</artifactId>
 <version>1.0</version>
 <scope>system</scope>
 <systemPath>${basedir}/lib/yournamejar.jar</sysyemPath>
</dependency>

Getting Started

  • In your main method call InitApp.run(YourStartupClass.class)
  • Annotate your startup class with @Service
  • Create a void method and annotate it with @StartUp

Here is a quick teaser of a complete project:

import org.example.annotations.Service;
import org.example.annotations.StartUp;
import org.example.container.DependencyContainer;
import org.example.container.DependencyContainerImpl;

@Service
public class Main
{
    private static final DependencyContainer dependencyContainer;
    static {
        dependencyContainer = new DependencyContainerImpl();
    }

    public static void main( String[] args ) {
        InitApp.run(Main.class);
    }

    @StartUp
    public void startUpMethod() {
        //coding here to get all the information about service classes from dependencyContainer variable
    }
}

Supported annotations by default:

  • Bean - Specify bean producing method.
  • Service - Specify service.
  • Autowired - Specify which constructor will be used to create instance of a service, also you can annotate fields with this annotation.
  • PostConstruct - Specify a method that will be executed after the service has been created.
  • PreDestroy - Specify a method that will be executed just before the service has been disposed.
  • StartUp - Specify the startup method for the app.

More info

If you are having trouble running the app, contact me at quangnam130520@gmail.com

About

Create my own IoC / Dependency Container


Languages

Language:Java 100.0%