Skip to content

Commit 91d05d5

Browse files
yt-msMidnighter
authored andcommitted
refactor: hold element in StaticStructureElementInstaance
1 parent 9ad70f0 commit 91d05d5

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/structurizr/model/container_instance.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from pydantic import Field
2222

23+
from .container import Container
2324
from .static_structure_element_instance import (
2425
StaticStructureElementInstance,
2526
StaticStructureElementInstanceIO,
@@ -28,7 +29,6 @@
2829

2930

3031
if TYPE_CHECKING:
31-
from .container import Container
3232
from .deployment_node import DeploymentNode
3333
from .model import Model
3434

@@ -45,12 +45,16 @@ class ContainerInstanceIO(StaticStructureElementInstanceIO):
4545
class ContainerInstance(StaticStructureElementInstance):
4646
"""Represents a container instance which can be added to a deployment node."""
4747

48-
def __init__(self, *, container: "Container", **kwargs) -> None:
48+
def __init__(self, *, container: Container, **kwargs) -> None:
4949
"""Initialize a container instance."""
5050
super().__init__(element=container, **kwargs)
51-
self.container = container
5251
self.tags.add(Tags.CONTAINER_INSTANCE)
5352

53+
@property
54+
def container(self) -> Container:
55+
"""Return the container for this instance."""
56+
return self.element
57+
5458
@property
5559
def container_id(self) -> str:
5660
"""Return the ID of the container for this instance."""

src/structurizr/model/software_system_instance.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ class SoftwareSystemInstance(StaticStructureElementInstance):
4848
def __init__(self, *, software_system: SoftwareSystem, **kwargs) -> None:
4949
"""Initialize a software system instance."""
5050
super().__init__(element=software_system, **kwargs)
51-
self.software_system = software_system
5251
self.tags.add(Tags.SOFTWARE_SYSTEM_INSTANCE)
5352

53+
@property
54+
def software_system(self) -> SoftwareSystem:
55+
"""Return the software system for this instance."""
56+
return self.element
57+
5458
@property
5559
def software_system_id(self) -> str:
5660
"""Return the ID of the software system for this instance."""

src/structurizr/model/static_structure_element_instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(
5555
# StaticStructureElementInstance.getName() in the Java API.
5656
kwargs["name"] = element.name
5757
super().__init__(**kwargs)
58+
self.element = element
5859
self.instance_id = instance_id
5960
self.health_checks = set(health_checks)
6061
self.parent = parent

0 commit comments

Comments
 (0)