We created the ViewModel and the repository.
Since we are using hilt for dependency injection, we need to create a module to tell hilt how to create
and provide dependencies to the rest of your app.
Please refer back to the previous sections and dependency injection sections, and especially dealing
with third party libraries like Firebase Retrofit and uh, and others in order to learn how to create
modules.
Why we use modules.
But don't worry I'll I'm going to clarify everything.
So please pay attention with me.
Since we are dealing with third party libraries like Firebase, we need to create modules to tell hilt
how to create and provide dependencies to the rest of your app.
Inside this package, create a new package named as die deferring for dependency injection.
New Kotlin object.
Name it as Firebase module.
Annotate it with module annotation and install in.
Set the singleton component class Alt+.
Enter singleton, not single component, singleton component and imported module.
This object contains methods that provide dependencies, so the Firebase module contains methods that
provide dependencies.
Install in annotation.
This says where these dependencies live.
Singleton component means these dependencies exist for the lifetime of your application.
They are singletons.
One shared instance of your whole application the Firebase module.
This is the Kotlin object.
It's a singleton itself.
No need to instantiate Firebase module.
Now we need to create the functions that this object provide.
We have the Firebase and the repository.
So let's start with Firebase Firestore.
Function provide Firebase Firestore and return Firebase Firestore.
Get instance Alt+.
Enter to import it.
And by the way thanks for the AI code completion and Gemini.
Okay this is a tool in Android Studio.
Then we need to add a new function called Provide Marker Repository Firestore and returns a marker repository
equals to marker repository implementation and pass via store.
In this object we created two functions.
The first function provide Firebase Firestore.
Returning type Firebase Firestore and it it calls Firebase Firestore dot get instance.
This this is the standard Firebase SDK way to get the singleton.
And here we provide marker repository Passing a parameter of type Firestore returning marker repository
and this equals to the marker repository and pass the firestore instance to it.
So I am calling this instance of marker repository and marker repository implementation and passing
the Firebase instance to it okay.
So those are the two functions we need to provide in order to tell hilt how to create and how to provide
them.
We need to annotate them with two annotations.
The first one is called provides.
And by the way I talked about provides annotation and singleton annotation a lot in the previous videos.
So please go back to learn more about singletons and provides provides.
This function tells hilt how to create Firebase Firestore.
Singleton annotation health will create one instance for the whole app.
The function body.
Return.
Firebase.
Firestore.
Get instance the standard Firebase SDK way to get the singleton.
So anywhere you ask for Firebase Firestore hilt gives you this instance.
Again guys anywhere you ask for Firebase Firestore instance hilt will provide you with this instance
okay.
This is the concept behind it.
Now let's create those two uh those two annotations in function.
And the function provide marker repository.
So provides and singleton again guys provides annotation.
This function tells hilt how to create a marker repository.
Firebase Firestore function and parameter.
Hilt sees that this parameter is needed.
It automatically calls provide firebase store function to get it equals to marker repository implementation
creates a new instance of your repository implementation passing Firestore into the constructor.
Singleton annotation.
Again, only one marker repository implementation exists in the app.
So anywhere you inject marker repository hilt uses this function to build it.
Okay.
So to get Firebase Firestore use Firebase Firestore dot get instance to get marker repository.
Build marker repository implementation with the Firestore instance.
Hill takes care of the order of creation the scooping singleton lifetime and passing dependencies automatically.