uklance / tiny-ioc Goto Github PK
View Code? Open in Web Editor NEWA lightweight IOC container inspired by google-guice and tapestry-ioc
License: Apache License 2.0
A lightweight IOC container inspired by google-guice and tapestry-ioc
License: Apache License 2.0
try / catch exception
<T> T ServiceRegistry.autobuild(Class<T> type)
@Service
public Foo createFoo(@Autobuild Bar bar) {
return new Foo(bar);
}
Currently context is not generic
ServiceBindOptions.withOrderedContributions(Class<?> type)
ServiceBindOptions.withUnorderedContributions(Class<?> type)
ServiceBindOptions.withMappedContributions(Class<?> keyType, Class<?> valueType)
This might require a ServiceDecorator
interface similar to ServiceBuilder
Ordering by before / after
@Contribute(serviceId="someService")
public void contributeSomeService(OrderedConfiguration<Foo> configuration) {
configuration.add("a", new Foo("abc"));
configuration.add("b", new Foo("xyz"));
}
If you don't define one it is considered proprietary.
public class Service {
@Inject private Foo foo; // not injected
}
<T> Map<String, T> getServices(Class<T> serviceType)
SystemPropertyProvider
StringPropertyProvider
DelegatePropertyProvider
getContributionKeyType
and getContributionValueType
should throw exception if contributionType
is not valid
setOrderedConfiguration(...)
setUnorderedConfiguration(...)
setMappedConfiguration(...)
Should be
setOrderedContributions(...)
setUnorderedContributions(...)
setMappedContributions(...)
DefaultModule
Autobuilder
DefaultServiceNameProvider
orderedContributions
takes a copy in the constructor (for sorting). Do this in the getter insteadgetContributionCollection
- rename to buildUnorderedContributions
getContributionList
- rename to buildOrderedContributions
getContributionMap
- rename to buildMappedContributions
dependencies.contributionType
switch to throw exceptioneg:
options.withOrder("before:*")
options.withOrder("before:foo", "after:bar")
options.withOrder("after:*")
Swap the order of the method parameters... currently:
public interface ServiceDecorator<T> {
T decorate(T delegate, ServiceBuilderContext context);
}
annotations & interfaces
Either environment variable or -P
install:
- ./gradlew assemble -Pci=true
script:
- ./gradlew check -Pci=true
http://stackoverflow.com/questions/17942819/how-can-i-get-clean-gradle-output-on-travis-ci
Binding Services
Default Service ID
Overriding Services
Decorating Services
Service Contributions
eg if ServiceBuilderContextImpl.getMappedContributions()
is called before ServiceBuilderContextImpl.setMappedContributions(Map contributions)
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;
}
Remember field.setAccessible(true)
for private
ServiceBinder only currently supports decorate by service type
Needs to work for annotations too
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.