DiamondLightSource / DiamondLightSource/dodal
Discussion: Architecture for inject
- Dominant language
- Python
- Stars
- 5
- Forks
- 13
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 10
Description
As a user of BlueAPI I would like to not have to specify my devices everytime I call a particular plan e.g.
```python
def initialise_detector(det: Eiger):
...
```
Should be able to be called from `BlueAPI` with no arguments specified as `BlueAPI` should already have all the devices and be able to use its existing `Eiger`.
There are a number of ways we could do this:
1) What we currently have:
```python
def initialise_detector(det:Eiger = ixx.eiger()):
pass
```
As discussed on https://github.com/DiamondLightSource/dodal/pull/854 this has the issue that it does work on import.
2) What we used to have:
```python
def initialise_detector(det:Eiger = inject("eiger_name")):
pass
```
This had the issue that it was hard to fix in pydantic 2.
3) A decorator approach:
```python
@inject(det="eiger_name")
def initialise_detector(det:Eiger):
pass
```
4) Passing the factory itself to inject without calling it:
```python
def initialise_detector(det:Eiger = inject(ixx.eiger)):
pass
```
5) Remove the magic entirely:
```python
def initialise_detector(det:Eiger|str = "eiger_name"):
if isinstance(det, str):
det = fetch_device(CONTEXT, det)
pass
```
## Acceptance Criteria
* Options are discussed by stakeholders
* A prototype implementation is written
Contributor guide
Assessment
This issue has not been assessed yet.