Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Register single dependency

See original GitHub issue

Is your feature request related to a problem? Please describe. When I need to register a single dependency, the current Laconia API is asking me to return an object, which lead to a verbose code.

const instances = ({ env }) => ({
  orderStream: new KinesisOrderStream(env.ORDER_STREAM_NAME)

exports.handler = laconia(kinesis(app))

Describe the solution you’d like

exports.handler = laconia(kinesis(app))
  .register("orderStream", ({env}) => new KinesisOrderStream(env.ORDER_STREAM_NAME) );

This will also allow users to decouple their factories better from Laconia:

exports.handler = laconia(kinesis(app))
  .register("orderStream", ({env}) => myOwnFactory(env.ORDER_STREAM_NAME) );

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

hugosenaricommented, Aug 12, 2019

Suggestion, add helper to convert to expected type:

const simple = (obj = {}) => deps => Object
    .reduce((result, [key, fn]) => ({ ...result, [key]: fn(deps) }), {});

const constants = (obj = {}) => () => Object
    .reduce((result, [key, value]) => ({ ...result, [key]: value }), {});


        orderStream: ({env}) =>  myOwnFactory(env.ORDER_STREAM_NAME)
        ONE: 1,
        foo: 'bar'
ceilforscommented, Sep 11, 2019

@hugosenari I didn’t realize how difficult it is to overload things in JavaScript, my bad. Maybe adding a new method is a good way to go, I’ll continue the conversation in the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency injection in ASP.NET Core | Microsoft Learn
The ASP.NET Core framework uses a convention for registering a group of related services. The convention is to use a single Add{GROUP_NAME} ...
Read more >
Is there a easier way to register dependencies when I want ...
In C#, of course, many dependencies can be registered for DI with one short line via Microsoft.Extensions.DependencyInjection, especially ...
Read more >
Registering Types with Prism
For those who may be familiar with ASP.NET Core you may be familiar with 3 basic types of dependency registrations: Transients, Singletons, and...
Read more >
Dependency Injection in ASP.NET Core - TutorialsTeacher
Learn about dependency injection in ASP.NET Core application. Undestand built-in IoC Container and basic registration of application services and its ...
Read more >
Instance Scope — Autofac 6.0.0 documentation
When a request is made for a service, Autofac can return a single instance (single instance scope), a new instance (per dependency scope),...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found