Git Product home page Git Product logo

Comments (7)

defval avatar defval commented on August 18, 2024

Hi @fionera! Thanks for your interest!

Fx is positioned as a framework. And di is just a container. The container's responsibilities are building the dependency graph, instantiate types, and invoking functions with these types. Control the application lifecycle is not part of these responsibilities.

At the same time, I try to build a composable system of reusable bundles for microservices development in an organization. And the functionality you want will be here. But I'm just getting started. Feel free to introduce your ideas and features :)

from di.

defval avatar defval commented on August 18, 2024

In the tutorial, you can see how I manage the lifecycle through a standard context, which will be canceled when the signal is received.

from di.

koolay avatar koolay commented on August 18, 2024

@fionera
Hi, why you switch fx to di?

from di.

defval avatar defval commented on August 18, 2024

@koolay Hi!

I can say for myself that after using FX for about a year in production, I encountered some problems that I tried to solve. I understand that Uber is a big company that can not do breaking changes in their libraries.

Relative to dependency injection:

The main point is associating interface with implementation. dig.As() could solve this problem, but the feature was not released.

Second is the use of tags for grouping. It was inconvenient for me. Grouping by interfaces looks more explicit. Also, groups in dig forced to use dig.In and dig.Out. It creates more complexity.

In third, lack of clean up.

As for framework, I use a different approach to grouping functionality, but this is a whole other story =)

from di.

fionera avatar fionera commented on August 18, 2024

The main point is associating interface with implementation. dig.As() could solve this problem, but the feature was not released.

Thats the exact reason why I want to switch to di. I already patched stuff into dig/fx since I needed/wanted them and it is far too verbose.

The reason why I would like to see a Lifecycle and StartStop System like fx in here, which could be made as a wrapping structure to the container, is that I have tens of Invokes that are in the modules of my App. I have to call the init for the db etc and I dont want to have to do this manually...

from di.

defval avatar defval commented on August 18, 2024

@fionera

You can group functional with di.Options() and use di.Invoke() option for initialization. On the compile stage invokes will be called:

var Database = di.Options(
	di.Provide(NewDatabase),
	di.Invoke(InitDatabase),
)

var Consul = di.Options(
	di.Provide(NewConsulClient),
	di.Invoke(RegisterInConsul),
)

func main() {
	c, err := di.New(
		Database,
		Consul,
	)
	if err != nil {
		// may database init failed or consul registration failed
	}
	// ...
}

Can this help?

from di.

defval avatar defval commented on August 18, 2024

Start/Stop will not be added to the container.

from di.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.