The injection Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The injection Reference Manual

This is the injection Reference Manual, version 0.1, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 04:04:45 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

* Injection
Dependency Injection for Common Lisp.

* Example calls
Set up a config file similar to the one found in examples/config.yml
(modeled after the PHP Symfony framework config):

#+BEGIN_SRC yaml
parameters:
  foo: bar
  an_array: [1, 2, 3]
  extra_config_file: "../example/config_only_params.yml"

services:
  file_loader:
    # 'factory:' is a function that will return an instance of the class we require,
    # since Common Lisp doesn't have position based class
    # constructors, a factory function is needed to map them to the class.
    factory: File-Loader-Factory
    arguments: ["%extra_config_file%"]

  service_container:
    factory: Container-Factory
    arguments: ["@file_loader"]
#+END_SRC

Note that the factory functions are assumed to do something equivalent
to the following (return a class instance as the return value):

#+BEGIN_SRC lisp
(defun File-Loader-Factory (your-input-arg)
  "Create an instance of a File-Loader or whatever class."
  (make-instance 'File-Loader :file-name your-input-arg))
#+END_SRC

Then load up your config file with:

#+BEGIN_SRC lisp
(injection:Container-Factory "/full/path/to/examples/config.yml" :singleton t)
#+END_SRC

This will create a global singleton instance of the last loaded config
that is stored in
#+BEGIN_SRC lisp
*container-singleton*
#+END_SRC
that you can access parameters and services from with these calls.

Access a parameter within it by using:
#+BEGIN_SRC lisp
(get-parameter "foo") -> "bar"
(get-parameter "an_array") -> '(1 2 3)
#+END_SRC

Access a service within it by using:
#+BEGIN_SRC lisp
(get-service "file_loader") -> #
(get-service "service_container") -> #
#+END_SRC

In case you didn't notice - yes, this is a sample config that is
chaining one container to another different config (you can do that no
problem!) - just be careful to avoid a circular loop or you may have
an issue.

* I will not use global scope Pam I am, I will not in a can
Ok, so, not a fan of global state, I understand.

You can avoid any global state by not specifying the singleton keyword
up above, and instead using the package as follows:

#+BEGIN_SRC lisp
(use-package :injection)

(let ((my-container (Container-Factory "example/config.yml")))
           (Container-Get-Parameter my-container "foo")) -> "bar"
#+END_SRC

Or even simplified to (assuming you only need one value out of there:
#+BEGIN_SRC lisp
(injection:Container-Get-Parameter (injection:Container-Factory "example/config.yml") "foo") -> "bar"
#+END_SRC

* Still on the agenda/caveats                                          :TODO:
At the moment, the YAML files are read from top to bottom, and this
means that you have to write them procedurally if injecting
dependencies (which you're likely to do if you wanted to use this to
begin with).

I might also add an optional *directory* keyword that would allow
specifying the location of a package to load (so you could actually
load packages or files on your machine through asdf/quicklisp through
the YAML configuration, instead of having to do it on your top level
asd yourself).

Essentially it would look something like this:
#+BEGIN_SRC yaml
services:
  service_container:
    factory: Container-Factory
    arguments: ["@file_loader"]
    directory: "/path/to/your-project"
    package: "package-name"
#+END_SRC

and would add the specified directory to your local quicklisp projects
directory, followed by a (ql:quickload :package-name), although that
may add needless complication.
* Installation
Clone the repository (you do know how to git clone by now right?)

Load the system with:
#+BEGIN_SRC lisp
(ql:quickload :injection)
(use-package :injection)
#+END_SRC

* License
GPLv3


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 injection

Author

Matthew Carter <m@ahungry.com>

License

GPLv3

Description

Dependency injection for Common Lisp

Version

0.1

Dependency

cl-yaml

Source

injection.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Modules

Modules are listed depth-first from the system components tree.


Next: , Previous: , Up: Modules   [Contents][Index]

3.1 injection/src/package

Parent

injection (system)

Location

src/package/

Component

package.lisp (file)


Next: , Previous: , Up: Modules   [Contents][Index]

3.2 injection/src/util

Dependency

src/package (module)

Parent

injection (system)

Location

src/util/

Component

generic.lisp (file)


Next: , Previous: , Up: Modules   [Contents][Index]

3.3 injection/src/classes

Dependency

src/util (module)

Parent

injection (system)

Location

src/classes/

Components

Previous: , Up: Modules   [Contents][Index]

3.4 injection/src/app

Dependency

src/classes (module)

Parent

injection (system)

Location

src/app/

Component

main.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

4.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.1 injection.asd

Location

injection.asd

Systems

injection (system)

Packages

injection-asd


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.2 injection/src/package/package.lisp

Parent

src/package (module)

Location

src/package/package.lisp

Packages

injection


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.3 injection/src/util/generic.lisp

Parent

src/util (module)

Location

src/util/generic.lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.4 injection/src/classes/Container.lisp

Dependency

file-loader.lisp (file)

Parent

src/classes (module)

Location

src/classes/Container.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Lisp files   [Contents][Index]

4.1.5 injection/src/classes/File-Loader.lisp

Parent

src/classes (module)

Location

src/classes/File-Loader.lisp

Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

4.1.6 injection/src/app/main.lisp

Parent

src/app (module)

Location

src/app/main.lisp


Next: , Previous: , Up: Top   [Contents][Index]

5 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

5.1 injection-asd

Source

injection.asd

Use List

Previous: , Up: Packages   [Contents][Index]

5.2 injection

Source

package.lisp (file)

Use List
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

6.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

6.1.1 Special variables

Special Variable: *container-singleton*
Package

injection

Source

container.lisp (file)


Next: , Previous: , Up: Exported definitions   [Contents][Index]

6.1.2 Functions

Function: container-factory FILE-NAME &key SINGLETON

Return an instance of CONTAINER class loaded up with FILE-NAME. If SINGLETON is t, also sets the *container-singleton* to the last loaded file, so the shortcut functions can be used to directly access the yml elements.

Package

injection

Source

container.lisp (file)

Function: get-parameter NAME

When the *container-singleton* is set, returns the service NAME.

Package

injection

Source

container.lisp (file)

Function: get-service NAME

When the *container-singleton* is set, returns the service NAME.

Package

injection

Source

container.lisp (file)


Previous: , Up: Exported definitions   [Contents][Index]

6.1.3 Generic functions

Generic Function: container-get-parameter CONTAINER NAME

Get a specific parameter NAME from CONTAINER.PARAMETERS.

Package

injection

Source

container.lisp (file)

Methods
Method: container-get-parameter (CONTAINER container) NAME
Generic Function: container-get-service CONTAINER NAME

Get a specific service NAME (class instance) from CONTAINER.SERVICES.

Package

injection

Source

container.lisp (file)

Methods
Method: container-get-service (CONTAINER container) NAME

Previous: , Up: Definitions   [Contents][Index]

6.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

6.2.1 Functions

Function: file-loader-factory FILE-NAME

Return an initialized FILE-LOADER class loaded up with FILE-NAME.

Package

injection

Source

file-loader.lisp (file)


Next: , Previous: , Up: Internal definitions   [Contents][Index]

6.2.2 Generic functions

Generic Function: container-expand-services CONTAINER ARGUMENTS

Look for arguments with the ’@’ symbol and expand.

Package

injection

Source

container.lisp (file)

Methods
Method: container-expand-services (CONTAINER container) ARGUMENTS

If we have any arguments that begin with an ’@’ symbol, we want to expand into the equivalent call to (Container-Get-Service container name).

Generic Function: container-instantiate-services CONTAINER

Instantiate each service (including dependent ones).

Package

injection

Source

container.lisp (file)

Methods
Method: container-instantiate-services (CONTAINER container)
Generic Function: container-load-file CONTAINER FILE-NAME

Load the YAML ’FILE-NAME’ into the CONTAINER.SERVICES and CONTAINER.PARAMETERS.

Package

injection

Source

container.lisp (file)

Methods
Method: container-load-file (CONTAINER container) FILE-NAME
Generic Function: content OBJECT
Generic Function: (setf content) NEW-VALUE OBJECT
Package

injection

Methods
Method: content (FILE-LOADER file-loader)

automatically generated reader method

Source

file-loader.lisp (file)

Method: (setf content) NEW-VALUE (FILE-LOADER file-loader)

automatically generated writer method

Source

file-loader.lisp (file)

Generic Function: file-name OBJECT
Generic Function: (setf file-name) NEW-VALUE OBJECT
Package

injection

Methods
Method: file-name (FILE-LOADER file-loader)

automatically generated reader method

Source

file-loader.lisp (file)

Method: (setf file-name) NEW-VALUE (FILE-LOADER file-loader)

automatically generated writer method

Source

file-loader.lisp (file)

Generic Function: instances OBJECT
Generic Function: (setf instances) NEW-VALUE OBJECT
Package

injection

Methods
Method: instances (CONTAINER container)

automatically generated reader method

Source

container.lisp (file)

Method: (setf instances) NEW-VALUE (CONTAINER container)

automatically generated writer method

Source

container.lisp (file)

Generic Function: load-content FILE-LOADER

Load FILE-LOADER.CONTENT based on FILE-LOADER.FILE-NAME.

Package

injection

Source

file-loader.lisp (file)

Methods
Method: load-content (FILE file-loader)
Generic Function: parameters OBJECT
Generic Function: (setf parameters) NEW-VALUE OBJECT
Package

injection

Methods
Method: parameters (CONTAINER container)

automatically generated reader method

Source

container.lisp (file)

Method: (setf parameters) NEW-VALUE (CONTAINER container)

automatically generated writer method

Source

container.lisp (file)

Generic Function: parse-yaml FILE-LOADER

Parse FILE-LOADER.CONTENT into FILE-LOADER.YAML.

Package

injection

Source

file-loader.lisp (file)

Methods
Method: parse-yaml (FILE file-loader)
Generic Function: services OBJECT
Generic Function: (setf services) NEW-VALUE OBJECT
Package

injection

Methods
Method: services (CONTAINER container)

automatically generated reader method

Source

container.lisp (file)

Method: (setf services) NEW-VALUE (CONTAINER container)

automatically generated writer method

Source

container.lisp (file)

Generic Function: yaml OBJECT
Generic Function: (setf yaml) NEW-VALUE OBJECT
Package

injection

Methods
Method: yaml (FILE-LOADER file-loader)

automatically generated reader method

Source

file-loader.lisp (file)

Method: (setf yaml) NEW-VALUE (FILE-LOADER file-loader)

automatically generated writer method

Source

file-loader.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

6.2.3 Classes

Class: container ()
Package

injection

Source

container.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
Direct slots
Slot: services
Initargs

:file-name

Readers

services (generic function)

Writers

(setf services) (generic function)

Slot: parameters
Initargs

:parameters

Readers

parameters (generic function)

Writers

(setf parameters) (generic function)

Slot: instances
Initargs

:instances

Initform

(make-hash-table :test (function equal))

Readers

instances (generic function)

Writers

(setf instances) (generic function)

Class: file-loader ()
Package

injection

Source

file-loader.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
Direct slots
Slot: name
Initargs

:file-name

Initform

""

Readers

file-name (generic function)

Writers

(setf file-name) (generic function)

Slot: content
Initargs

:content

Readers

content (generic function)

Writers

(setf content) (generic function)

Slot: yaml
Initargs

:yaml

Readers

yaml (generic function)

Writers

(setf yaml) (generic function)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   F   I   L   M  
Index Entry  Section

F
File, Lisp, injection.asd: The injection<dot>asd file
File, Lisp, injection/src/app/main.lisp: The injection/src/app/main<dot>lisp file
File, Lisp, injection/src/classes/Container.lisp: The injection/src/classes/container<dot>lisp file
File, Lisp, injection/src/classes/File-Loader.lisp: The injection/src/classes/file-loader<dot>lisp file
File, Lisp, injection/src/package/package.lisp: The injection/src/package/package<dot>lisp file
File, Lisp, injection/src/util/generic.lisp: The injection/src/util/generic<dot>lisp file

I
injection.asd: The injection<dot>asd file
injection/src/app: The injection/src/app module
injection/src/app/main.lisp: The injection/src/app/main<dot>lisp file
injection/src/classes: The injection/src/classes module
injection/src/classes/Container.lisp: The injection/src/classes/container<dot>lisp file
injection/src/classes/File-Loader.lisp: The injection/src/classes/file-loader<dot>lisp file
injection/src/package: The injection/src/package module
injection/src/package/package.lisp: The injection/src/package/package<dot>lisp file
injection/src/util: The injection/src/util module
injection/src/util/generic.lisp: The injection/src/util/generic<dot>lisp file

L
Lisp File, injection.asd: The injection<dot>asd file
Lisp File, injection/src/app/main.lisp: The injection/src/app/main<dot>lisp file
Lisp File, injection/src/classes/Container.lisp: The injection/src/classes/container<dot>lisp file
Lisp File, injection/src/classes/File-Loader.lisp: The injection/src/classes/file-loader<dot>lisp file
Lisp File, injection/src/package/package.lisp: The injection/src/package/package<dot>lisp file
Lisp File, injection/src/util/generic.lisp: The injection/src/util/generic<dot>lisp file

M
Module, injection/src/app: The injection/src/app module
Module, injection/src/classes: The injection/src/classes module
Module, injection/src/package: The injection/src/package module
Module, injection/src/util: The injection/src/util module

Jump to:   F   I   L   M  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   (  
C   F   G   I   L   M   P   S   Y  
Index Entry  Section

(
(setf content): Internal generic functions
(setf content): Internal generic functions
(setf file-name): Internal generic functions
(setf file-name): Internal generic functions
(setf instances): Internal generic functions
(setf instances): Internal generic functions
(setf parameters): Internal generic functions
(setf parameters): Internal generic functions
(setf services): Internal generic functions
(setf services): Internal generic functions
(setf yaml): Internal generic functions
(setf yaml): Internal generic functions

C
container-expand-services: Internal generic functions
container-expand-services: Internal generic functions
container-factory: Exported functions
container-get-parameter: Exported generic functions
container-get-parameter: Exported generic functions
container-get-service: Exported generic functions
container-get-service: Exported generic functions
container-instantiate-services: Internal generic functions
container-instantiate-services: Internal generic functions
container-load-file: Internal generic functions
container-load-file: Internal generic functions
content: Internal generic functions
content: Internal generic functions

F
file-loader-factory: Internal functions
file-name: Internal generic functions
file-name: Internal generic functions
Function, container-factory: Exported functions
Function, file-loader-factory: Internal functions
Function, get-parameter: Exported functions
Function, get-service: Exported functions

G
Generic Function, (setf content): Internal generic functions
Generic Function, (setf file-name): Internal generic functions
Generic Function, (setf instances): Internal generic functions
Generic Function, (setf parameters): Internal generic functions
Generic Function, (setf services): Internal generic functions
Generic Function, (setf yaml): Internal generic functions
Generic Function, container-expand-services: Internal generic functions
Generic Function, container-get-parameter: Exported generic functions
Generic Function, container-get-service: Exported generic functions
Generic Function, container-instantiate-services: Internal generic functions
Generic Function, container-load-file: Internal generic functions
Generic Function, content: Internal generic functions
Generic Function, file-name: Internal generic functions
Generic Function, instances: Internal generic functions
Generic Function, load-content: Internal generic functions
Generic Function, parameters: Internal generic functions
Generic Function, parse-yaml: Internal generic functions
Generic Function, services: Internal generic functions
Generic Function, yaml: Internal generic functions
get-parameter: Exported functions
get-service: Exported functions

I
instances: Internal generic functions
instances: Internal generic functions

L
load-content: Internal generic functions
load-content: Internal generic functions

M
Method, (setf content): Internal generic functions
Method, (setf file-name): Internal generic functions
Method, (setf instances): Internal generic functions
Method, (setf parameters): Internal generic functions
Method, (setf services): Internal generic functions
Method, (setf yaml): Internal generic functions
Method, container-expand-services: Internal generic functions
Method, container-get-parameter: Exported generic functions
Method, container-get-service: Exported generic functions
Method, container-instantiate-services: Internal generic functions
Method, container-load-file: Internal generic functions
Method, content: Internal generic functions
Method, file-name: Internal generic functions
Method, instances: Internal generic functions
Method, load-content: Internal generic functions
Method, parameters: Internal generic functions
Method, parse-yaml: Internal generic functions
Method, services: Internal generic functions
Method, yaml: Internal generic functions

P
parameters: Internal generic functions
parameters: Internal generic functions
parse-yaml: Internal generic functions
parse-yaml: Internal generic functions

S
services: Internal generic functions
services: Internal generic functions

Y
yaml: Internal generic functions
yaml: Internal generic functions

Jump to:   (  
C   F   G   I   L   M   P   S   Y  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
C   I   N   P   S   Y  
Index Entry  Section

*
*container-singleton*: Exported special variables

C
content: Internal classes

I
instances: Internal classes

N
name: Internal classes

P
parameters: Internal classes

S
services: Internal classes
Slot, content: Internal classes
Slot, instances: Internal classes
Slot, name: Internal classes
Slot, parameters: Internal classes
Slot, services: Internal classes
Slot, yaml: Internal classes
Special Variable, *container-singleton*: Exported special variables

Y
yaml: Internal classes

Jump to:   *  
C   I   N   P   S   Y  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   F   I   P   S  
Index Entry  Section

C
Class, container: Internal classes
Class, file-loader: Internal classes
container: Internal classes

F
file-loader: Internal classes

I
injection: The injection system
injection: The injection package
injection-asd: The injection-asd package

P
Package, injection: The injection package
Package, injection-asd: The injection-asd package

S
System, injection: The injection system

Jump to:   C   F   I   P   S