/stiletto

A super simple kotlin dependency injector

Primary LanguageKotlinApache License 2.0Apache-2.0

Stiletto

Stiletto

The implmentation of Stiletto just in one file, which you can just copy to your codebase instead of importing by maven or something fancy. The interesting parts are in the usage and configuration, which is what the sample app is for.

Modules are just interfaces with stateless "provider" functions and wrapped with singleton (and an optional tag) if needed.

Module dependencies are defined by abstract properties to be passed in as contructor params, or abstract methods to be fulfilled by other modules. Unfulfilled dependencies are thus checked compile time when creating the component.

Components are simply classes that use "multiple inheritance" of the Module interfaces and inherit some abstract behavior to handle holding singletons. In most cases as in the example, they shouldn't contain any implmentation as that's already provided by the Module functions.

Component dependencies are fulfilled via Class Delegation.

License

Copyright 2015 Vincent Mi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.