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

Use decorators to set a service definition #33

Open
shiroyuki opened this issue Nov 8, 2018 · 3 comments
Open

Use decorators to set a service definition #33

shiroyuki opened this issue Nov 8, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@shiroyuki
Copy link
Owner

@shiroyuki shiroyuki commented Nov 8, 2018

While XML is a powerful ML, not many people like working with XML. So, there are a few feedbacks on how writing service definition can be improved.

Instead of using XML, we borrow the idea of component scanning from Spring Beans by allowing developers to define the definitions in Python (beside #21).

# the ready-to-go standalone container already implemented
from imagination.standalone import container

container.configure('myapp.config')
container.configure('library_1.config')
# ...
container.configure('library_n.config')
from imagination.decorators import config

@config(scan=['myapp.submodule_1', '...', 'myapp.submodule_n'])
class MyAppConfigurationA:
    # ...
from imagination.decorator.stereotype  import component

@component
class Dependency1Class:
      # ...
from imagination.decorator import auto_wired
from imagination.decorator.stereotype  import component, identifier

@auto_wired
@component
@identifier('myapp.service.one')
class Service1:
      dependency1: Dependency1Class

This is borrowed the idea from Flask and the presumably discontinued Spring-Python.

@shiroyuki shiroyuki added the v3 label Nov 8, 2018
@shiroyuki shiroyuki added this to the Version 3 milestone Nov 8, 2018
@shiroyuki shiroyuki added v3 and removed v3 labels Nov 8, 2018
@shiroyuki shiroyuki modified the milestone: Version 3 Nov 8, 2018
@shiroyuki shiroyuki self-assigned this Nov 13, 2018
shiroyuki added a commit that referenced this issue Nov 15, 2018
shiroyuki added a commit that referenced this issue Nov 15, 2018
… Dorian Pula and a few people I discussed with at PyCon Canada 2018 Sprint Session for critical feedback.
@shiroyuki
Copy link
Owner Author

@shiroyuki shiroyuki commented Nov 27, 2018

In the 3.0.0-dev.1 release, the code will look like this.

from imagination import service
from imagination.decorator.config import (default_id_by_fully_qualify_class_name,
                                          default_id_by_shorten_fully_qualify_class_name,
                                          default_id_by_qualify_class_name,
                                          default_id_by_class_name,
                                          Parameter as PrimitiveParameter,
                                          Service as ServiceParameter)

@service.registered(
    params=[
        PrimitiveParameter('Panda', 'name'),
        ServiceParameter(SimpleSampleService, 'simple_sample', default_id_by_class_name),
    ],
    default_service_id_generator=default_id_by_class_name
)
class Foo:
    # ...

However, the end goal should be something like:

@generate_service_id(by_class_name)
@inject(SimpleSampleService, 'simple_sample')
@define(name='Panda')
@service.registered
class Foo:
    simple_sample:SimpleSampleService
    # ...
@shiroyuki
Copy link
Owner Author

@shiroyuki shiroyuki commented Dec 6, 2018

The commit c3b994c should resolve the basic requirement for this issue. Until there is a proper documentation, please check out https://github.com/shiroyuki/Imagination/blob/master/test/v3/test_imagination_decorator_config.py for sample usage.

@shiroyuki
Copy link
Owner Author

@shiroyuki shiroyuki commented Dec 11, 2018

Service scanning is required for this task.

@shiroyuki shiroyuki reopened this Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant