blubber / django_injector Goto Github PK
View Code? Open in Web Editor NEWDependency injection in Django.
License: BSD 2-Clause "Simplified" License
Dependency injection in Django.
License: BSD 2-Clause "Simplified" License
Is there an option to inject a dependency into a signal handler? Or at least an option to create a custom scope outside the request handling pipeline?
I made my configuration like so :
`INSTALLED_APPS = [
'django_injector',
]
MIDDLEWARE = [
'django_injector.middleware.inject_request_middleware'
]
INJECTOR_MODULES = [
'garderie.manager.bidings.Container'
]`
I have my bindings like this :
class Container(Module): def configure(self, binder): binder.bind(DateUtils, to='DateUtils') binder.bind(PaymentService, to='PaymentService') binder.bind(PaymentSynchronizer, to='PaymentSynchronizer') binder.bind(PaymentScheduler, to='PaymentScheduler') binder.bind(PaymentAPIService, to='PaymentAPIService') binder.bind(PaymentAPIImpl, to='PaymentAPIImpl') binder.bind(PaymentAPIMapper, to='PaymentAPIMapper') binder.bind(InscriptionService, to='InscriptionService')
yet I get this error when I run my server :
AttributeError: 'DjangoInjectorModule' object has no attribute '__name__'
Hi,
I'm the creator of the dry-python project. We have an alternative dependency injection library: dependencies.
I hope you can take a look at it and provide some feedback to us.
We have Django and REST Framework integration as well:
I know the issue tracker isn't the best way to share ideas. Forgive me if it confuses you in any way.
Best regards,
Artem.
Hi!
May be this info will save some time to users.
Issue description:
The reason (as I understant, it's may be wrong) is than django_injector adds wrapper to view GraphQLView and removes
.csrf_exempt = True
from view
Just for now I removed django_injector from project, because for me just injector works good with graphene-django
But may be it will be good to solve this issue.
Hello,
Thank you for this great package. Can you please tell me when it will become compatible with Django 3.1?
I haven't found how to do dependency injection for a specific application, it can only be done globally, it would be convenient to add scope for a specific django apps:
class PollsClientModule(Module):
@app("polls")
@singleton
@provider
def provide_client(self) -> ABCMyClient:
...
class CatsClientModule(Module):
@app("cats")
@singleton
@provider
def provide_client(self) -> ABCMyClient:
...
polls/views.py:
def index_view(request: HttpRequest, client: ABCMyClient) -> HttpResponse: # ABCMyClient from PollsClientModule
...
cats/views.py:
def index_view(request: HttpRequest, client: ABCMyClient) -> HttpResponse: # ABCMyClient from CatsClientModule
...
Hello everyone, after updating the library to the latest version, I try to run my project but I get the following error related to this library, do you have any idea why it could be happening?
I have the following libraries installed:
In addition to the above, the following tests were performed, but they did not work either:
1 - Django and DRF in current version (4.0.4 and 3.xx) and updating Django-Injector version to 0.3.1.
2- Django and DRF to the latest version without upgrading Django-Injector (0.2.5)
3- Django and DRF to the latest version with the latest version of Django-Injector (0.3.1)
File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/utils/module_loading.py", line 32, in import_string
raise ImportError(
ImportError: Module "django_injector" does not define a "inject_request_middleware" attribute/class
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/opt/homebrew/Cellar/[email protected]/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 157, in inner_run
handler = self.get_handler(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 78, in get_handler
return get_internal_wsgi_application()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'config.wsgi.application' could not be loaded; Error importing module.
Hello,
First of all thank you for your amazing work.
On the new version 0.3.0 the package is not fully downloaded.
Thank you for a nice package, but I have an issue with novel version.
Python version 3.9.1
Django version 3.1.6
That code example raises an exception
from injector import inject
class Command(BaseCommand):
""" Remove expired login tokens """
help = 'Remove expired tokens'
@inject
def __init__(self, case: RemoveExpiredRestoreTokens, *args, **kwargs):
super().__init__(*args, **kwargs)
self._case: RemoveExpiredRestoreTokens = case
def handle(self, *args, **options):
self._case.execute()
self.stdout.write(self.style.SUCCESS('Expired restore tokens were removed'))
Exception
Traceback (most recent call last): File "/code/manage.py", line 22, in <module> main() File "/code/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 244, in fetch_command klass = load_command_class(app_name, subcommand) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 38, in load_command_class return module.Command() TypeError: __init__() missing 1 required positional argument: 'case'
But it works on previous version of package (0.1.1) with the usage of modified inject decorator for django-inject package
from django_injector import inject
class Command(BaseCommand):
""" Remove expired login tokens """
help = 'Remove expired tokens'
@inject # type: ignore
def __init__(self, case: RemoveExpiredRestoreTokens, *args, **kwargs):
super().__init__(*args, **kwargs)
self._case: RemoveExpiredRestoreTokens = case
def handle(self, *args, **options):
self._case.execute()
self.stdout.write(self.style.SUCCESS('Expired restore tokens were removed'))
Also now is absent ability to inject into functions and inject Injector itself. If you need access to Container
Smth like this
from django_injector import inject
from injector import Injector
@inject
def get_container(injector: Injector) -> Injector:
""" Returns container instance """
return injector
Can you suggest smth or I should use previous version?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.