All Projects → Exelord → solid-services

Exelord / solid-services

Licence: MIT license
Solid.js library adding a services layer for global shared state.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to solid-services

SwiftInjection
Dependency Injection framework for Swift
Stars: ✭ 21 (-38.24%)
Mutual labels:  dependency-injection
lightsaber
Compile time dependency injection framework for JVM languages. Especially for Kotlin.
Stars: ✭ 119 (+250%)
Mutual labels:  dependency-injection
component-manager
component framework and dependency injection for golang
Stars: ✭ 21 (-38.24%)
Mutual labels:  dependency-injection
magnet
Dependency injection library for modular Android applications
Stars: ✭ 174 (+411.76%)
Mutual labels:  dependency-injection
inject
[Archived] See https://github.com/goava/di.
Stars: ✭ 49 (+44.12%)
Mutual labels:  dependency-injection
mvp-architecture-kotlin-dagger-2-retrofit-android
Android Application MVP (Model-View-Presenter) architecture example using Dagger2 Dependency Injection (DI) and Retrofit Tutorial using Kotlin programming language.
Stars: ✭ 15 (-55.88%)
Mutual labels:  dependency-injection
definject
Unobtrusive Dependency Injector for Elixir
Stars: ✭ 46 (+35.29%)
Mutual labels:  dependency-injection
DependencyInjector
Lightweight dependency injector
Stars: ✭ 30 (-11.76%)
Mutual labels:  dependency-injection
di
🛠 A full-featured dependency injection container for go programming language.
Stars: ✭ 156 (+358.82%)
Mutual labels:  dependency-injection
di-comparison
DI containers comparison
Stars: ✭ 20 (-41.18%)
Mutual labels:  dependency-injection
AutoDI
Dependency injection made simple.
Stars: ✭ 87 (+155.88%)
Mutual labels:  dependency-injection
noicejs
extremely thin async dependency injection
Stars: ✭ 16 (-52.94%)
Mutual labels:  dependency-injection
tsdi
Dependency Injection container (IoC) for TypeScript
Stars: ✭ 50 (+47.06%)
Mutual labels:  dependency-injection
toolkit
some useful library of the php
Stars: ✭ 15 (-55.88%)
Mutual labels:  dependency-injection
solid
Solid Android components
Stars: ✭ 33 (-2.94%)
Mutual labels:  dependency-injection
di
一个简易版本的Go依赖注入实现
Stars: ✭ 133 (+291.18%)
Mutual labels:  dependency-injection
android-base-project
Android LateralView Base Project
Stars: ✭ 25 (-26.47%)
Mutual labels:  dependency-injection
Spork
Annotation processing and dependency injection for Java/Android
Stars: ✭ 77 (+126.47%)
Mutual labels:  dependency-injection
Mimick.Fody
An integrated framework for dependency injection and aspect-oriented processing.
Stars: ✭ 15 (-55.88%)
Mutual labels:  dependency-injection
unbox
Fast, simple, easy-to-use DI container
Stars: ✭ 45 (+32.35%)
Mutual labels:  dependency-injection

Solid Services logo

Solid Services

Services are "global" objects useful for features that require shared state or persistent connections. They are lazy evaluated, only when used, solving an issue of cross dependencies and contexts tree.

Example uses of services might include:

  • User/session authentication
  • Geolocation
  • WebSockets
  • Server-sent events or notifications
  • Server-backed API calls libraries
  • Third-party APIs
  • Logging

Installation

npm i solid-services

Compatibility

  • Solid.js ^1.0

Demo

Open on CodeSandbox

Using a ServiceRegistry

ServiceRegistry will create a context around your components allowing you to scope the services to specific part of the application.

// app.tsx
import { ServiceRegistry } from 'solid-services';

export default App(props) {
  return (
    <ServiceRegistry>
      {props.children}
    </ServiceRegistry>
  )
}

Defining a service

To define a service define a function that returns an instance of a class or a POJO object.

// eg. ./services/auth.ts

export function AuthService() {
  const [getUser, setUser] = createSignal();

  return {
    get user() {
      return getUser();
    },

    login(user) {
      setUser(user);
    },

    logout() {
      setUser(undefined)
    },
  }
}

Accessing a service

To access a service in your components or other services use useService(). It will register a service or return existing object if it was already used in the past.

// components/logout.tsx
import { useService } from "solid-services";
import AuthService from "../services/auth";

export default function LogoutComponent() {
  const authService = useService(AuthService)
  
  function logout() {
    authService().logout();  
  }
  
  return <button onClick={logout}>Logout<button>
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].