# Acessor
## Description
`acessor` is a library to make it easy to orchestrate multiple services while using Elixir processes.
## Installation
the package can be installed by adding `acessor` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:acessor, "~> 0.1.1"}
]
end
```
## Run tests
```sh
mix test
```
## Usage
```elixir
defmodule MyModule do
use Acessor.Macros.Service
def hello(name) do
"Hello, " <> name
end
end
services = %{:mymodule => MyModule}
Acessor.config(services) # true
{:response, response} = Acessor.invoke(:mymodule, :hello, ["Bob"])
assert response == "Hello, Bob"
```
## Use Cases
`acessor` is useful when you have multiple services in your ecosystem, and you need to invoke them all the time. This could eliminate code duplication where all services could be centralized inside a library/repo for example:
```elixir
# this could be a new library/repo used across services
defmodule MyService1 do
def make_rest_request(_), do: :rest1
end
defmodule MyService2 do
def make_rest_request(_), do: :rest2
end
services = %{:service_1 => MyService1, :service_2 => MyService2}
Acessor.config(services)
Acessor.invoke(:service_1, :make_rest_request, []) # {:response, :rest1}
Acessor.invoke(:service_2, :make_rest_request, []) # {:response, :rest2}
```
## Methods
`config/1 - services (inside %{})`
this method adds your services to the acessor, making it possible to invoke any methods after this initial setup.
`invoke/3 - service_name, method, args (inside [])`
this method uses `GenServer` to invoke your registered service, returning:
`{:response, response}` or `{:noresponse, nil}`