Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic service registration #571

Open
dariuszd21 opened this issue Nov 29, 2024 · 5 comments
Open

dynamic service registration #571

dariuszd21 opened this issue Nov 29, 2024 · 5 comments
Assignees

Comments

@dariuszd21
Copy link
Contributor

What needs to get done

Add an API that allows to create dynamically ServiceFactory from the given sequence or extend the existing one to be able to create services on demand,

Why it needs to get done

We want to be able to register additional services dynamically through the API, without relying on inheritance.

To be able to do dynamically define a ServiceFactory extended with all the services provided by our application / library.

We should be able to create a factory dynamically by just specifying additional services that should be included without an inheritance dance.

import craft_lib
import craft_application

additional_services = craft_lib.get_services()
service_factory = craft_application.ServiceFactory.with_additional_services(additional_services)
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3738.

This message was autogenerated

@lengau
Copy link
Contributor

lengau commented Nov 29, 2024

I'd rather give the ServiceFactory a register classmethod that lets you register different services to the factory.

@dariuszd21
Copy link
Contributor Author

dariuszd21 commented Nov 29, 2024

I'd rather give the ServiceFactory a register classmethod that lets you register different services to the factory.

That's why it's a spike as I think that the final implementation will be much different than an example 😅

@lengau
Copy link
Contributor

lengau commented Dec 2, 2024

In fact thinking more about it, I think the ServiceFactory could even drop the entire concept of "native" services and use register for everything. That'd be a breaking change that we don't need to do now, but the registration should allow it to happen.

We might even be able to use this to help with lazy loading of service modules. E.g. if you were to register the services like:

craft_application.ServiceFactory.register("provider", "snapcraft.services.provider.Provider")

then snapcraft.services.provider only needs to be imported when we load the provider service (meaning that craft-providers and its dependencies only need to be imported when we load the provider service).

@lengau lengau self-assigned this Dec 2, 2024
@dariuszd21
Copy link
Contributor Author

In fact thinking more about it, I think the ServiceFactory could even drop the entire concept of "native" services and use register for everything. That'd be a breaking change that we don't need to do now, but the registration should allow it to happen.

We might even be able to use this to help with lazy loading of service modules. E.g. if you were to register the services like:

craft_application.ServiceFactory.register("provider", "snapcraft.services.provider.Provider")

then snapcraft.services.provider only needs to be imported when we load the provider service (meaning that craft-providers and its dependencies only need to be imported when we load the provider service).

I'm all for the register approach replacing inheritance. I can't wait to see the prototype 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants