Skip to content

Commit 4a7d874

Browse files
committed
Add ServiceLocator member
1 parent 16d8721 commit 4a7d874

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/app.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ constexpr auto context_ci = le::Context::CreateInfo{
1111
} // namespace
1212

1313
App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")) {
14+
bind_services();
15+
1416
// test code, remove later.
15-
if (auto json = dj::Json{}; m_data_loader.load_json(json, "test_file.json")) { log.info("loaded JSON: {}", json); }
17+
auto json = dj::Json{};
18+
if (m_services.get<le::IDataLoader>().load_json(json, "test_file.json")) { log.info("loaded JSON: {}", json); }
1619
}
1720

1821
void App::run() {
@@ -24,4 +27,11 @@ void App::run() {
2427
m_context.present();
2528
}
2629
}
30+
31+
void App::bind_services() {
32+
m_services.bind(&m_context);
33+
// m_data_loader is bound to both the interface and the concrete class for use through either type.
34+
m_services.bind<le::IDataLoader>(&m_data_loader);
35+
m_services.bind<le::FileDataLoader>(&m_data_loader);
36+
}
2737
} // namespace miracle

src/app.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <le2d/context.hpp>
33
#include <le2d/file_data_loader.hpp>
4+
#include <le2d/service_locator.hpp>
45

56
namespace miracle {
67
class App {
@@ -10,7 +11,11 @@ class App {
1011
void run();
1112

1213
private:
14+
void bind_services();
15+
1316
le::Context m_context;
1417
le::FileDataLoader m_data_loader{};
18+
19+
le::ServiceLocator m_services{};
1520
};
1621
} // namespace miracle

0 commit comments

Comments
 (0)