AppContext

com.github.rssh.appcontext.AppContext
object AppContext

Application context is a way, to resolve components dependencies. Each component should provide an AppContextProvider, and AppContext[Component] will instantiate this components with dependencies.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
AppContext.type

Members list

Type members

Classlikes

class In[F[_]]

Async access to application context in effect F.

Async access to application context in effect F.

 val asyncAppContext = AppContext.In[Durable]()
 val service = asyncAppContext[EmailService]  // returns Durable[EmailService]

Type parameters

F
  • effect type

Attributes

Supertypes
class Object
trait Matchable
class Any

Types

opaque type Cache

Type for component cache. By convention, if component depends from cache then it's AppContextProvider should check if this component is already in cache and instantiate new (and update cache) only if it's not found.

Type for component cache. By convention, if component depends from cache then it's AppContextProvider should check if this component is already in cache and instantiate new (and update cache) only if it's not found.

Attributes

opaque type CacheKey[T]

Type for cache key. By convention, usually this is a type.show.

Type for cache key. By convention, usually this is a type.show.

Attributes

Value members

Concrete methods

def apply[T](using AppContextProviderLookup[T]): T

Get component from application context. For this component should have an implicit AppContextProvider. When called inside a class with AppContextProviders[(X, Y, ...)], the providers from that tuple take precedence over AppContextProvider[X] defined in X's companion object.

Get component from application context. For this component should have an implicit AppContextProvider. When called inside a class with AppContextProviders[(X, Y, ...)], the providers from that tuple take precedence over AppContextProvider[X] defined in X's companion object.

Type parameters

T
  • component to instantiate

Attributes

See also

AppContextProvider

AppContextProviderLookup

inline def cacheKey[T]: CacheKey[T]
def customCacheKey[T](key: String): CacheKey[T]

Create empty cache.

Create empty cache.

Attributes

Returns

empty cache

Extensions

Extensions

extension (c: Cache)
inline def get[T]: Option[T]

Get component from cache.

Get component from cache.

Type parameters

T
  • component type

Attributes

Returns

Some(component) or None if component is not found.

inline def getOrCreate[T](value: => T): T

Get component from cache or create new one and update cache.

Get component from cache or create new one and update cache.

Type parameters

T
  • component type

Value parameters

value
  • function to create new component

Attributes

Returns

just created or cached component

inline def modify[T](f: (Option[T]) => Option[T]): Unit

Modify component in cache.

Modify component in cache.

Type parameters

T
  • component type

Value parameters

f
  • function to remap

Attributes

inline def put[T](value: T): Option[T]

Put component to cache, replacing old if needed

Put component to cache, replacing old if needed

Attributes

inline def remove[T]: Option[T]

Remove component from cache.

Remove component from cache.

Type parameters

T
  • component type

Attributes