GithubHelp home page GithubHelp logo

tchigher / serviceagency Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huxq17/serviceagency

0.0 0.0 0.0 534 KB

A gradle plugin that decouples through detach interface and its implementation.

License: Apache License 2.0

Groovy 26.31% Java 69.04% CMake 4.02% C++ 0.63%

serviceagency's Introduction

ServiceAgency

Android Arsenal

Introduction

这是一个将接口和实现完全分离的gradle插件,适用于在使用第三方框架时进行解耦的场景。只需要在实现类上添加ServiceAgent注解,ServiceAgency会在项目构建阶段自动将实现和接口关联,开发者在使用的时候不需要传入实现,可以通过把ServiceAgent注解添加到另一个实现类上来达到快速替换实现的目的,具体看下面。

This is a gradle plugin that completely separates the interface and its implementation,suitable for decoupling when using third-party frameworks. Use by adding ServiceAgent annotation on interface's implementation class. ServiceAgency will auto associate interface and its implementation during the build phase,so we can use interface without its implementation completely.The usage is as follows.

Config build.gradle:

Root project build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.buyi.huxq17:agencyplugin:1.2.0'
    }
}

App module build.gradle:

apply plugin: 'service_agency'

Example:

Define interface and its implementation

Interface:

public interface ImageLoader {
    void loadImage(String url, ImageView imageview);
}

Implements and add ServiceAgent annotation:

@ServiceAgent
public class ImageLoaderImpl implements ImageLoader {

    @Override
    public void loadImage(String url, ImageView imageview) {
        Picasso.with(WXEnvironment.getApplication()).load(url).into(imageview);
    }

}

Usage:

   ImageLoader imageLoader = ServiceAgency.getService(this,ImageLoader.class);
          //getServiceWithoutCache will not cache service's instance.
          //ImageLoader imageLoader = ServiceAgency.getServiceWithoutCache(this,ImageLoader.class);
          imageLoader.test("MainActivity onCreate");
          //OR
          INetworkClient networkClient = ServiceAgency.getService(INetworkClient.class);
          networkClient.get();
          //Release memory if need.
          ServiceAgency.clear();

Change Logs

2019-4-5:
1.Add getService(Context, Class<T>) and getServiceWithoutCache(Context, Class<T>) method,release v1.2.0.
2019-4-4:
1.Fix bugs,release v1.1.3.
2018-11-16:
1.Fix bugs,release v1.1.2.
2018-9-30:
1.Support Instant Run and release v1.1.0.

LICENSE

Apache License 2.0

serviceagency's People

Contributors

huxq17 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.