- Constructor Injection
- Field (or Property) Injection
- Method (or Setter) Injection
Shadhin's Notebook
This is my personal collection of daily lessons, professional insights, and programming experiences. It’s a space where I document what I learn, and you can explore and learn from my journey too.
Wednesday, September 25, 2024
Pros and Cons of the three fundamental types of Dependency Injection (DI)
Three fundamental types of Dependency Injection (DI)
The three fundamental types of Dependency Injection (DI) in Kotlin and Java are:
- Constructor Injection
- Field (or Property) Injection
- Method (or Setter) Injection
Each type of DI handles injecting dependencies into a class in different ways. Let's explore these in detail:
1. Constructor Injection
With constructor injection, the dependencies are passed through a class constructor. This is the most common and preferred form of dependency injection because it makes the class more explicit and easier to test. The dependencies are required at the time of object creation.
This example effectively illustrates the principles of Dependency Injection
Dependency Injection (DI) is a software design pattern that promotes loose coupling between classes by passing dependencies (objects that a class needs to function) into the class rather than having the class create them itself. This makes code more modular, testable, and maintainable.
Here's a simplified example of how DI works:
Wednesday, January 25, 2023
Flutter command not found , How to Permanently add Flutter Path in Mac OS
- Download the latest Flutter version from the official site.
- Unzip it and move it to Any location on your Mac.
- Open Terminal Any Type sudo nano /etc/paths
- Add this to the file: /Users/yourUserName/Development/flutter/bin (it is actually your flutter bin location)
- Save the file by pressing Ctrl + X then Y and then Enter.
- Close the terminal and reopen it again.
- Run: flutter doctor -v
- Done
Thursday, January 19, 2023
Xcode error 'building for iOS Simulator, but linking in dylib built for iOS .. for architecture arm64' from Apple Silicon M1 Mac
Add This at the end of your Podfile,
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
then Command pod install
command not found: brew macos (Mac is M1-based)
If your shell is zsh and your Mac is M1-based, enter these two commands after installing brew:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofileeval "$(/opt/homebrew/bin/brew shellenv)"
The first command adds:
- an expanded
PATHvariable that includes the directories wherebrewand commands installed withbreware located - several shell variables used by
brew
to the .zprofile initialization file.
The second command adds those same variables to the current shell, so that you can start using brew without re-reading .zprofile.
- PS: For Intel Macs, use
/usr/localinstead of/opt/homebrew. - PPS: If you are running
bash, use.bashrcinstead of.zprofile.
Tuesday, January 17, 2023
install_failed_user_restricted miui 13 after Deny during first time installation
In my case, I pressed Deny unfortunately during the first time installation. So I was getting INSTALL_FAILED_USER_RESTRICTED.
1) Turn ON Developer Options
Settings > About phone > keep tapping ‘ MIUI version ‘ until it says you’re a developer.
2)Settings->Additional Settings->Developer Options
First For MIUI global 13 and above to turn off MIUI optimization
- go to the developer option
- go down where button one was "Reset to default values"
- press it 5 times or more,
- then the turn-off MIUI optimization is visible
3) Turn ON USB Debugging
4) Turn OFF MIUI optimization
5) Turn ON Install via USB All Done
Tuesday, September 13, 2022
Update particular item's value from a list of data class Kotlin
Your data class should have mutable properties so that they can be changed:
fun <T> updateWorkerData(id: Int, property: KMutableProperty1<Worker, T>, value: T) { val workers = getListOfWorker() workers.forEach { if (it.id == id) { property.set(it, value) } } } updateWorkerData(1, Worker::age, 28)
Wednesday, May 25, 2022
Git Commands (Clone a specific Git branch)
git clone -b <your branch> <remote_repo url>
Example:
git clone -b myBranch https://github.com/shadhin/java.git
