laeta


License

License

MIT
GroupId

GroupId

com.leobenkel
ArtifactId

ArtifactId

laeta_2.11
Last Version

Last Version

0.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

laeta
laeta
Project URL

Project URL

https://github.com/leobenkel/Laeta
Project Organization

Project Organization

com.leobenkel
Source Code Management

Source Code Management

https://github.com/leobenkel/Laeta

Download laeta_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.leobenkel/laeta_2.11/ -->
<dependency>
    <groupId>com.leobenkel</groupId>
    <artifactId>laeta_2.11</artifactId>
    <version>0.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.leobenkel/laeta_2.11/
implementation 'com.leobenkel:laeta_2.11:0.0.4'
// https://jarcasting.com/artifacts/com.leobenkel/laeta_2.11/
implementation ("com.leobenkel:laeta_2.11:0.0.4")
'com.leobenkel:laeta_2.11:jar:0.0.4'
<dependency org="com.leobenkel" name="laeta_2.11" rev="0.0.4">
  <artifact name="laeta_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.leobenkel', module='laeta_2.11', version='0.0.4')
)
libraryDependencies += "com.leobenkel" % "laeta_2.11" % "0.0.4"
[com.leobenkel/laeta_2.11 "0.0.4"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 3.0.5

Project Modules

There are no modules declared in this project.

License: MIT Gitter release-badge maven-central-badge Build Status BCH compliance Coverage Status Mutation testing badge

Laeta

Small library to handle registery of services.

Handle collection of Services of arbitrary type and retrieve them fully typed.

Laeta (wikipedia)

Table of Contents

Created by gh-md-toc

How to use?

Add to build.sbt

First include the library in your project:

libraryDependencies += "com.leobenkel" %% "laeta" % "[VERSION]"

With version being: maven-central-badge

Setup

Live example: Scastie-0P5GodpCSSmL5Pd8igL0tA or take a look at the test example

You need two pieces for the compiler to start guiding you:

A service:

import com.leobenkel.laeta.Service

case class MyService(override val input: INPUT) extends Service[INPUT, MyService] {
 ???
}

And a factory:

import com.leobenkel.laeta.ServiceFactory

case class MyFactory(override val getInput: Int) extends ServiceFactory[INPUT, MyService] {
    lazy override protected val getObject: ServiceConstructor[INPUT, MyService] = MyConstructor
    lazy override protected val getType:   ServiceType[MyService] = MyGeyKey
}

This will force you to create:

A constructor:

object MyConstructor extends ServiceConstructor[INPUT, MyService]

Your MyConstructor should probably have the same name as case class MyService so you don't have to implement the apply method.

and a Type:

case object MyGeyKey extends ServiceType[MyService] {}

To use

And to use is very simple, you first register all the factories:

val registryBuilder: RegistryFactories = RegistryFactories()
    .register(MyFactory(input))

and then you seal the registry:

val registryReady: ServiceCollection = registryBuilder.create

you can now access any service, anywhere, typed !

val myService = registryReady.getService(MyGeyKey)

Notes

It is possible to merge the ServiceConstructor[INPUT, MyService] and the ServiceType[MyService] for shorter code.

This mean you can replace all the places where we used MyGeyKey by MyConstructor.

Example on Scastie-716dNpMORwuJqO9RWED93A.

Versions

Version
0.0.4
0.0.2
0.0.1