「依存性の注入」=「依存されるオブジェクトの注入」
依存する実装を定義したinterfaceをつくり、そのinterfaceをstruct(構造体)のフィールドとして持たせる
from multiprocessing import Process, Manager | |
class MyMap(): | |
def __new__(cls): | |
self = Manager().dict() | |
return self | |
def f(d): | |
d[1] += '1' | |
d['2'] += 2 |
class dict2(dict): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.__dict__ = self |
import logging | |
import aioredis | |
class RedisConn: | |
_pool = {} | |
# Singleton | |
def __new__(cls, *args, **kwargs): | |
if not hasattr(cls, "_instance"): |
{ | |
Type = { | |
key : Text, | |
}, | |
default = { | |
key = "default", | |
} | |
} |
λ(n : Natural) -> [ n, n + 1 ] |
import React from 'react'; | |
import AppContainer from './appcontainer'; | |
export default function App() { | |
return ( | |
<AppContainer /> | |
) | |
} |
「依存性の注入」=「依存されるオブジェクトの注入」
依存する実装を定義したinterfaceをつくり、そのinterfaceをstruct(構造体)のフィールドとして持たせる
#!/usr/bin/env python3 | |
import os | |
from sqlalchemy import create_engine | |
## assertion | |
for key in ['USERNAME', 'PASSWORD', 'HOST', 'DATABASE']: | |
assert os.getenv(key), f'{key} is empty' | |