![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Inversion-of-control container for all your dependency injection needs.
Sack is meant to be used with Browserify, so install with npm:
npm install sack
This is a simple Inversion of Control Container. It provides the mechanism you need to have a centralized store of object instances that other types can passive request get injected.
This means that you can have objects use, access, or compose other objects without having to explicitly know how to create / setup / initialize them.
It lets you have a highly-decoupled and framework-independent domain objects.
The functionality of Sack lies within its Container
class.
Register a dependency with a container with a stringly-typed tag and either a constructor, instance, or closure.
var Container = require('sack').Container;
var container = new Container();
// Create a new instance every request:
container.register('service', MyService);
// Create a new instance on first request, then reuse (singleton-esque):
container.shared('service', MyService);
// Use an existing instance:
container.register('service', new Service());
// Have a (lazily evaluated) callback provide the dependency every request
container.register('service', function() {
return new MyService();
});
// Use a callback to provide the dependency, but only once (singleton):
container.shared('service', function() {
return new MyService();
});
You can create / request objects via the make()
function.
var service = container.make('service');
Whenever Sack creates an object, it satisfies that object's dependencies by resolving them out of the container as well.
An object expresses its dependency as a constructor parameter, whose name must match a registered object.
function UserEditController(users)
{
this.users = users;
}
UserEditController.prototype.refreshUsers()
{
this.users.refresh();
}
Assuming we have registered some implementation for users
:
container.register('users', new LocalStorageUsers());
Then making UserEditController
via the container will resolve the dependency
automatically.
var controller = container.make(UserEditController);
The source files are all decorated with JSDoc3-style
annotations that work great with the Tern code inference
system. Combined with the Node plugin (see this project's .tern-project
file), you can have intelligent autocomplete for methods in this library.
Testing is done with Tape and can be run
with the command npm test
.
Automated CI cross-browser testing is provided by Testling.
Copyright 2014 Brandon Valosek
Sack is released under the MIT license.
1.0.0 (2014-01-19)
FAQs
An Inversion-of-Control container for all your dependency injection needs.
The npm package sack receives a total of 13 weekly downloads. As such, sack popularity was classified as not popular.
We found that sack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.