Package: django-hexdi
django-hexdiThis is the project that integrateshexdiframework into Django.Visitgithub pageofhexdiproject for use-cases and instructions.Created for using with django-based applications.Installationpipinstalldjango-hexdiKeep in mind that we really recommend to use the same version of hexdi
that django-hexdi hasUsageFirst step is to adddjhexdito yourINSTALLED_APPSsetting.Imagine next project tree:app_folder
|-->__init__.py
|-->services.py
|-->concrete_services.py
.....
|-->urls.py
|-->forms.py
|-->views.pyFile services.py contains service class declarations and “interfaces”.File concrete_services.py contains implementations of services stored
in services.py and binded usinghexdicalls.forms.py, views.py, and so on use services.py interfaces and inject
these interfaces implementations usinghexdiinjections.So, there are several ways to set uphexdion Django for static or
automatic implementations loading:Dummy strategyThis is thedefault strategythat does nothing on application
startup. You really should use something other!HEXDI_STRATEGY='djhexdi.strategy.Dummy'Static strategyThis is the simplest and static strategy of implementations discovery
using modules list that contain bindings.Use next setting to set up this strategy:HEXDI_STRATEGY='djhexdi.strategy.Static'Use the special setting to provide dotted path of modules where bindings
are presented:HEXDI_MODULES_LIST=['path.to.first.module','path.to.second.module',]You can specify a module that contains this list:HEXDI_MODULE='__hexdi__'Use this discovery when you are sure that there is no other place with
bindings and your dependency modules don’t use hexdi, so on.Fully automatic strategyThis is the dynamic strategy of modules finding which works on
application startup.Use next setting to set up this strategy:HEXDI_STRATEGY='djhexdi.strategy.Auto'By default,hexdiwill search in packages that presented inINSTALLED_APPS. But, you can also specify your special packages for
searching using following setting:HEXDI_FINDER_PACKAGES=['path.to.first.package','path.to.second.package',]You can also specify a static modules to load it additionally if it is
needed:HEXDI_MODULES_LIST=['path.to.first.module','path.to.second.module',]And you can specify a number of modules that should be excluded from
loading:HEXDI_EXCLUDE_MODULES=['path.to.first.excluded.module','path.to.second.excluded.module',]Use this strategy if you canrely on module-finderor your
dependencies are usinghexdi, or something.But keep in mind thatthis strategy may slowdown your application
startupif you have a huge number of modules/dependencies.Pre-build automatic discovery with static loadingThis is the best configuration for application that has a build process
or same thing.Workflow explanationBuild process:requirements installationother build activities (migrations, caching, template building, etc.)modules automatic discovery and storing results in py-file artifactRun application:application startpre-searched artifact loading with modules list on application
startup processSetup Django projectDefine setting for using static strategy:HEXDI_STRATEGY='djhexdi.strategy.Static'Define a file where discovered modules will be stored:HEXDI_MODULE='__hexdi__'The best way is to use__hexdi__as HEXDI_MODULE value.By default,hexdiwill search in packages that presented inINSTALLED_APPS. But, you can also specify your special packages for
searching using following setting:HEXDI_FINDER_PACKAGES=['path.to.first.package','path.to.second.package',]You can also define modules that should be loaded additionallyHEXDI_MODULES_LIST=['path.to.first.module','path.to.second.module',]Set up build stepUse the special manage.py command for modules automatic discoveryIf you have configured your Django project withHEXDI_MODULEsetting
then you can just apply following command:pythonmanage.pydi_find--autoIf you want to specify some other module, just use -m option:pythonmanage.pydi_find-mother.module.path--auto–autooption is used for automatic creation of packages tree if not
exists.Use this strategy when you have too much dependencies to store all
modules manually and if you have build process with controllable build
steps. That configuration allows you to havefully automatic
discoveryonce while build process and thenquick application
startupwith cached module paths.All supported settingsList of built-in settings and it’s descriptionHEXDI_STRATEGY- Strategy for DI container bindings discovery
used on application startup. Should be inherited fromdjhexdi.strategy.AbstractStrategyclass. Default valuedjhexdi.strategy.Dummy;HEXDI_FINDER_PACKAGES- A list of packages(dotted paths). By
default usesINSTALLED_APPSmodules list. Used byAutomatic strategyanddi_findmanagement command;HEXDI_MODULES_LIST- A list of modules(dotted paths) that should
be loaded on application startup. Used byStatic strategyandAutomatic strategy;HEXDI_EXCLUDE_MODULES- A list of modules that should be excluded
from module-loading. Used byStatic loadingandAutomatic loading;HEXDI_MODULE_LIST_NAME- A name of variable with modules list
that should be presented in module(HEXDI_MODULE setting). Used byStatic strategyanddi_findmanagement command;HEXDI_MODULE- A module path(dotted path) that contains a
variable(name stores in HEXDI_MODULES_LIST_NAME) with list of
module paths(dotted paths). Used byStatic strategy,Automatic strategy, anddi_findmanagement command.HEXDI_LOADER- A string contained dotted path to a class that
will be used asmodule loader. Default valuehexdi.loader.BasicLoaderHEXDI_FINDER- A string contained dotted path to a class that
will be used asmodule finder. Default valuehexdi.finder.RecursiveRegexFinderCustom strategyIf you have some other vision of startup loading strategy, then you are
able to implement it.Check moduledjhexdi.strategyfor useful abstract classes and
functions:functionload_modulesloads found or specified modules. Accepts
modules list(dotted paths) as a first argument and modules to
exclude(dotted paths) as a second argument. Uses loader specified inHEXDI_LOADERsetting;functionfind_modulesdiscover modules. Accepts packages
list(dotted paths) to find as a single argument. Uses finder
specified inHEXDI_FINDERsetting;classAbstractStrategyis a very base abstract class that
provides methodgowithout arguments for doing some module-load
staff on application startup. All other strategies should be
inherited from that class.classAbstractLoadModulesStrategyis an abstract strategy
inherited fromAbstractStrategyand provides implemented methodgoand 2 other methods: discover_modules - abstract method that
should return a modules list, get_excluded_modules - already
implemented method that returns a list presented inHEXDI_EXCLUDE_MODULESsetting.classStaticis a ready-to-go strategy inherited fromAbstractLoadModulesStrategywith implemented behaviour of static
modules list(HEXDI_MODULES_LIST) loading and module
loading(HEXDI_MODULE). You can inherit from that class and extend
static loading with some other staff.classAutois a ready-to-go strategy inherited fromStaticstrategy and extended it with automatic discovery of modules to load.Check modulehexdi.utilsfor useful functions