Skip to content

Commit b8c7d2a

Browse files
committed
README Updated
1 parent d8a382c commit b8c7d2a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int main() {
6565
container.Install<IPrinter>(std::make_unique<Printer>());
6666

6767
// Retrieve and use
68-
auto printer = container.GetIface<IPrinter>();
68+
auto printer = container.Get<IPrinter>();
6969
printer->Print("Hello, SimplisticDI!");
7070

7171
return 0;
@@ -85,13 +85,12 @@ container.Install<IConsoleLogger>(std::move(uniqueObj)); // Takes ownership
8585
```
8686
2. **Shared Ownership:** The container shares ownership using `std::shared_ptr`.
8787
```cpp
88-
auto sharedObj = std::make_shared<ConsoleLogger>(2);
89-
container.SharedInstall(sharedObj); // Shares ownership
88+
container.Install(std::make_shared<ConsoleLogger>(2)); // Shares ownership
9089
```
9190
3. **Non-Ownership Reference:** The container stores a raw pointer without taking ownership.
9291
```cpp
9392
ConsoleLogger localObj(3);
94-
container.BindIface<IConsoleLogger>(&localObj); // No ownership, user manages lifetime
93+
container.Bind<IConsoleLogger>(&localObj); // No ownership, user manages lifetime
9594
```
9695
9796
**Compact Example:**
@@ -123,14 +122,14 @@ int main() {
123122
sdi::Container container;
124123
container
125124
.Install<IPrinter>(std::move(uniquePrinter)) // Unique ownership
126-
.SharedInstall(sharedPrinter) // Shared ownership
127-
.BindIface<IPrinter>(&localPrinter) // No ownership, reference
128-
.Bind(42) // Bind value
129-
.Bind(3.14f); // Bind another value
125+
.Install(sharedPrinter) // Shared ownership
126+
.Bind<IPrinter>(&localPrinter) // No ownership, reference
127+
.Install(42) // Bind value
128+
.Install(3.14f); // Bind another value
130129
131-
container.GetIface<IPrinter>()->Print("Hello, DI!");
130+
container.Get<IPrinter>()->Print("Hello, DI!");
132131
133-
std::cout << container.Get<int>() << " " << container.Get<float>() << std::endl;
132+
std::cout << container.GetO<int>() << " " << container.GetO<float>() << std::endl;
134133
135134
return 0;
136135
}
@@ -143,8 +142,8 @@ In SimplisticDI:
143142

144143
1. **Ownership Management:**
145144

146-
- **Unique Ownership:** When a `std::unique_ptr` is bound, the container takes full ownership. The object is freed when the container is destroyed or if the unique pointer is replaced by another.
147-
- **Shared Ownership:** When a `std::shared_ptr` is bound, the container shares ownership with other parts of the program. The object remains valid as long as any `shared_ptr` references it, and is not replaced by another one.
145+
- **Unique Ownership:** When a `std::unique_ptr` is installed, the container takes full ownership. The object is freed when the container is destroyed or if the unique pointer is replaced by another.
146+
- **Shared Ownership:** When a `std::shared_ptr` is installed, the container shares ownership with other parts of the program. The object remains valid as long as any `shared_ptr` references it, and is not replaced by another one.
148147
2. **Non-Ownership References:**
149148

150149
- **Raw Pointers:** When a raw pointer is bound, the container does not manage the object's lifecycle. The object must be managed and freed by the user. The container only stores the pointer.

0 commit comments

Comments
 (0)