Comments (7)
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.
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.
@fionera
Hi, why you switch fx to di?
from di.
@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.
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.
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.
Start/Stop will not be added to the container.
from di.
Related Issues (20)
- Unable to make interfaces group by using the same funtion interface implenentations HOT 11
- container.Resolve() doesn't create signleton when dependency requested via intermidiate constructor HOT 2
- No documentation for the *Container.Has() method HOT 1
- Using `di.WithName()` breaks when having one entry without a `di.Name()` HOT 7
- Parameter structs need an empty di tag on an entry else it gets ignored HOT 1
- Allow decorating of services in the container HOT 8
- concurrent map read and map write HOT 6
- Duplicate instance with di.As HOT 2
- Singleton HOT 1
- Handle embed unnamed dependency HOT 1
- Improve tracing HOT 2
- Support the ability to chain containers (to form scopes) HOT 3
- Change how Injected structs are tagged HOT 4
- Why should I pass a pointer to the type? HOT 2
- Possibility to disable singleton behavior. HOT 5
- Important: Upcoming Transfer of This Repository on June 5th
- Issue after package name migration HOT 4
- Provide values via custom string types HOT 2
- Overriding a value from a parent di container
- Factory function returning other di.Provide HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from di.