(+) Application Layer - environment
Environment ์ ํ์์ฑ
๊ฐ์ ์ข ๋ฅ์ด์ง๋ง ๋น๋ ํ๊ฒฝ์ ๋ฐ๋ผ์ ๊ฐ์ด ๋ฌ๋ผ์ ธ์ผํ๋ ๊ฒ๋ค์ด ์๋ค. ๊ฐ์ฅ ํฐ ์๋ก ๊ฐ๋ฐ ์๋ฒ, ์ด์ ์๋ฒ์ ์๋ํฌ์ธํธ๊ฐ ์๋ค. ํ์ง๋ง ์ด๋ฅผ ์ํด์ ํ๋ก๋์ ์ฝ๋์ ๊ฐ๋ฐ ์ฝ๋๋ฅผ ๊ตฌ๋ถํด์ ๊ฐ๋ฐํ๋ ๊ฒ์ ์๋ชป๋ ๊ฐ๋ฐ์ด๋ค. ๋ชจ๋ ํ ์คํธ์ ๊ฐ๋ฐ์ ํ๋ก๋์ ์ ๊ธฐ์ค์ผ๋ก ์๋ํ๊ณ ๊ตฌํ๋์ด์ผํ๋ค.
๋ฐ๋ผ์ ์ฝ๋ ๋ด์์ ํ๋ก๋์ ์ฝ๋์ ๊ฐ๋ฐ ์ฝ๋๊ฐ ๊ตฌ๋ถ๋์ง ์๊ณ ์ผ๊ด๋๊ฒ ํ๋ก๋์ ์ฝ๋๋ก ๊ตฌํ๋๋๋ก ํ๋ ๋น๋ ํ๊ฒฝ์ ๋ฐ๋ผ ๋ฌ๋ผ์ ธ์ผํ ๊ฐ๋ค์ ๋ค๋ฅด๊ฒ ์ฌ์ฉ ๋๋๋ก ํด์ผํ๋ค. ์ด๋ฅผ ์ํด์ ํ๊ฒฝ์ ๋ํด์๋ง ๋ถ๊ธฐ ์ฒ๋ฆฌ๋ฅผ ํ๊ณ ๊ทธ ์ธ์๋ ๋ชจ๋ ๋์ผํ ํ๋ก๋์ ์ฝ๋์์ ํ๊ฒฝ ๋ณ๋ก ๋ค๋ฅธ ๊ฐ์ ๊ฐ๊ณ ๋์ํ๋๋ก ์ฒ๋ฆฌํด์ผํ๋๋ฐ ์ด๋ฅผ Environment ๊ฐ ์ฒ๋ฆฌํ๋๋ก ํ๋ค.
VM ์ต์ ์ ํ์ฉํด๋ ๋ ๊ฒ ๊ฐ์๋๋ฐ ์ผ๋จ ์ฑ ๊ธฐ๋์ ์ง์ ์ง์ ์ ์์ ๋ค๋ฅด๊ฒ ์ค์ ํ์ฌ ์ฝ๋ ๋ด์ enum ์ผ๋ก ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํด๋๋ ๋ฐฉ์์ ์ทจํ๋ค.
ํจํค์ง ๊ตฌ์ฑ ๊ด์ ์์ ๋ฐ๋ผ๋ณธ Environment
Environment ๊ตฌํ
development.dart(production.dart ๋ ๋์ผํ ๋ฐฉ์)
void main() {
final Environment environment =
Environment.newInstance(EnvironmentType.development);
environment.run();
}
environment.dart
import 'package:app_frame_sample/app.dart';
import 'package:flutter/cupertino.dart';
import '../application.dart';
class Environment {
static Environment? _instance;
final EnvironmentType environmentType;
const Environment._internal(this.environmentType);
static bool get _isDevelopment {
return _instance!.environmentType == EnvironmentType.development;
}
static bool get _isProduction {
return _instance!.environmentType == EnvironmentType.production;
}
static String get baseUrl {
if (_isDevelopment) {
return 'http://localhost:8080';
}
if (_isProduction) {
return 'http://localhost:8090';
}
throw UnsupportedError(ErrorMessage.notFoundEnvironmentType);
}
factory Environment.newInstance(EnvironmentType environmentType) {
_instance ??= Environment._internal(environmentType);
return _instance!;
}
void run() async {
WidgetsFlutterBinding.ensureInitialized();
await Injector.prepareDependencies();
runApp(const Application());
}
}
Last updated