This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'com.google.dagger:dagger:2.10' | |
annotationProcessor 'com.google.dagger:dagger-compiler:2.10' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Inek { | |
@Inject | |
public Inek(){ | |
} | |
public void otla() { | |
Log.d("Otlatma Bilgisi","Inek otluyor"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Koyun { | |
@Inject | |
public Koyun(){ | |
} | |
public void otla() { | |
Log.d("Otlatma Bilsidi","Koyun otluyor"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Ciftlik { | |
private Inek inek; | |
private Koyun koyun; | |
@Inject | |
public Ciftlik(Inek inek, Koyun koyun) { | |
this.inek = inek; | |
this.koyun = koyun; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class CiftlikModule { | |
private Context context; | |
public CiftlikModule(Application app){ | |
this.context=app; | |
} | |
@Provides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component(modules = {CiftlikModule.class}) | |
public interface CiftlikComponent { | |
void inject(MainActivity activity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MvpApp extends Application { | |
private CiftlikComponent ciftlikComponent; | |
public CiftlikComponent getCiftlikComponent() { | |
return ciftlikComponent; | |
} | |
public void setCiftlikComponent(CiftlikComponent ciftlikComponent) { | |
this.ciftlikComponent = ciftlikComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="net.ozaydin.serkan.daggerexample"> | |
<application | |
android:name=".MvpApp" | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Inject | |
Ciftlik ciftlik; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Inject | |
Ciftlik ciftlik; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
((MvpApp) getApplication()).getCiftlikComponent().inject(MainActivity.this); |