GithubHelp home page GithubHelp logo

uklance / tiny-ioc Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 5.0 189 KB

A lightweight IOC container inspired by google-guice and tapestry-ioc

License: Apache License 2.0

Java 100.00%
ioc ioc-container

tiny-ioc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tiny-ioc's Issues

@Autobuild

<T> T ServiceRegistry.autobuild(Class<T> type)

@Service
public Foo createFoo(@Autobuild Bar bar) {
   return new Foo(bar);
}

Support services contributions

ServiceBindOptions.withOrderedContributions(Class<?> type)
ServiceBindOptions.withUnorderedContributions(Class<?> type)
ServiceBindOptions.withMappedContributions(Class<?> keyType, Class<?> valueType)

Support decorate

This might require a ServiceDecorator interface similar to ServiceBuilder

Annotation based contributions

@Contribute(serviceId="someService")
public void contributeSomeService(OrderedConfiguration<Foo> configuration) {
   configuration.add("a", new Foo("abc"));
   configuration.add("b", new Foo("xyz"));
}

PropertyProviders

SystemPropertyProvider
StringPropertyProvider
DelegatePropertyProvider

Rename contribution setters in ServiceBuilderContextImpl

  1. getContributionKeyType and getContributionValueType should throw exception if contributionType is not valid

setOrderedConfiguration(...)
setUnorderedConfiguration(...)
setMappedConfiguration(...)

Should be

setOrderedContributions(...)
setUnorderedContributions(...)
setMappedContributions(...)

Refactor ServiceReference

  • orderedContributions takes a copy in the constructor (for sorting). Do this in the getter instead
  • getContributionCollection - rename to buildUnorderedContributions
  • getContributionList - rename to buildOrderedContributions
  • getContributionMap - rename to buildMappedContributions
  • Add a default case to the dependencies.contributionType switch to throw exception

ServiceReference.get() without synchronized

See lock-free-and-wait-free-thread-safe-lazy-initialization

Busy spin

private AtomicBoolean canWrite = new AtomicBoolean(false);  
private volatile Foo foo; 
public Foo getInstance() {
   while (foo == null) {
       if(canWrite.compareAndSet(false, true)){
           foo = new Foo();
       }
   }
   return foo;
}

Synchronized creation

private final AtomicReference<Foo> instance = new AtomicReference<>(null);
public Foo getInstance() {
  Foo foo = instance.get();
  if (foo == null) {
    synchronized(instance) {
      // You need to double check here
      // in case another thread initialized foo
      Foo foo = instance.get();
      if (foo == null) {
        foo = new Foo(); // actual initialization
      }
    }
  }
  return foo;
}

Decorate by serviceId

ServiceBinder only currently supports decorate by service type
Needs to work for annotations too

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.