Popular New Releases in Dependency Injection
guice
Guice 5.1.0
InversifyJS
v6.0.1
wire
0.5.0
Swinject
v2.8.0
Autofac
v6.3.0
Popular Libraries in Dependency Injection
by golang go
13170 NOASSERTION
Go dependency management tool experiment (deprecated)
by google java
10791 Apache-2.0
Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 8 and above, brought to you by Google.
by inversify typescript
8776 MIT
A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
by square java
7274 Apache-2.0
A fast dependency injector for Android and Java.
by google go
6383 Apache-2.0
Compile-time Dependency Injection for Go
by JakeWharton java
5740 Apache-2.0
A sample Android app which showcases advanced usage of Dagger among other open source libraries.
by Swinject swift
4802 MIT
Dependency injection framework for Swift with iOS/macOS/Linux
by autofac csharp
3843 MIT
An addictive .NET IoC container
by symfony php
3706 MIT
The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.
Trending New libraries in Dependency Injection
by hadashiA csharp
666 MIT
The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.
by YairHalberstadt csharp
621 MIT
compile time dependency injection for .NET
by adonovan go
621 BSD-2-Clause
Spaghetti: a dependency analysis tool for Go packages
by pakrym csharp
595 MIT
C# Source Generator based dependency injection container implementation.
by skydoves kotlin
271 Apache-2.0
😴 A lazy and fluent syntactic sugar for Android and ViewModel Lifecycle properties.
by mandarineorg typescript
198 MIT
Mandarine.TS is a typescript, decorator-driven framework that allows you to create server-side applications. Mandarine.TS provides a range of built-in solutions such as Dependency Injection, Components, ORM and more. Under its umbrella, Mandarine.TS has 4 modules: Core, Data, Security and MVC, these modules will offer you the requirements to build a Mandarine-powered application.
by googlecodelabs kotlin
158 Apache-2.0
by FuzzySecurity csharp
128
BlueHatIL 2020 - Staying # and Bringing Covert Injection Tradecraft to .NET
by NtRaiseHardError c
113
NINA: No Injection, No Allocation x64 Process Injection Technique
Top Authors in Dependency Injection
1
14 Libraries
4502
2
6 Libraries
19999
3
4 Libraries
3152
4
4 Libraries
8
5
4 Libraries
25
6
4 Libraries
422
7
4 Libraries
337
8
4 Libraries
940
9
3 Libraries
83
10
3 Libraries
276
1
14 Libraries
4502
2
6 Libraries
19999
3
4 Libraries
3152
4
4 Libraries
8
5
4 Libraries
25
6
4 Libraries
422
7
4 Libraries
337
8
4 Libraries
940
9
3 Libraries
83
10
3 Libraries
276
Trending Kits in Dependency Injection
No Trending Kits are available at this moment for Dependency Injection
Trending Discussions on Dependency Injection
dependency injection life cycle for IDisposable classes in .NET core
How to use appsettings.json in Asp.net core 6 Program.cs file
Android Build Error: "lStar not found..."
How to register ServiceBusClient for dependency injection?
How to create beans dynamically using a DI framework
What is the difference between static class and singleton in .net mvc project?
.NET Core Dependency Injection how to handle multiple objects
Does using Spring boot with javafx will consume a lot of memory?
.Net 6 Console app: WebApplication.CreateBuilder vs Host.CreateDefaultBuilder
Android Instrumented tests with KodeIn
QUESTION
dependency injection life cycle for IDisposable classes in .NET core
Asked 2022-Mar-29 at 09:28I want to know, what is the best way to dispose the all IDisposable object after the request done.
AddTransient<T>
- adds a type that is created again each time it's requested.AddScoped<T>
- adds a type that is kept for the scope of the request.AddSingleton<T>
- adds a type when it's first requested and keeps hold of it.
So, singleton could not be a good choice because it will disposes after app shot down. but scope and transient are good candidates. I have a repository which I want to create a connection with my db like this:
1public class Dapperr : IDapper
2 {
3 private readonly IConfiguration _config;
4 private string Connectionstring = "DefaultConnection";
5
6 public Dapperr(IConfiguration config)
7 {
8 _config = config;
9 }
10 public void Dispose()
11 {
12
13 }
14
15
16 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
17 {
18 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
19 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
20 }
21
22 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
23 {
24 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
25 return db.Query<T>(sp, parms, commandType: commandType).ToList();
26 }
27}
28
Now In my start up I'm going to add dependency injection:
1public class Dapperr : IDapper
2 {
3 private readonly IConfiguration _config;
4 private string Connectionstring = "DefaultConnection";
5
6 public Dapperr(IConfiguration config)
7 {
8 _config = config;
9 }
10 public void Dispose()
11 {
12
13 }
14
15
16 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
17 {
18 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
19 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
20 }
21
22 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
23 {
24 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
25 return db.Query<T>(sp, parms, commandType: commandType).ToList();
26 }
27}
28services.AddScoped<IDapper, Dapperr>();
29
I want to know if I am allow to remove All those using
scop because of adding scope dependency. for example like this:
1public class Dapperr : IDapper
2 {
3 private readonly IConfiguration _config;
4 private string Connectionstring = "DefaultConnection";
5
6 public Dapperr(IConfiguration config)
7 {
8 _config = config;
9 }
10 public void Dispose()
11 {
12
13 }
14
15
16 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
17 {
18 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
19 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
20 }
21
22 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
23 {
24 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
25 return db.Query<T>(sp, parms, commandType: commandType).ToList();
26 }
27}
28services.AddScoped<IDapper, Dapperr>();
29public class Dapperr : IDapper
30 {
31 private readonly IConfiguration _config;
32 private string Connectionstring = "DefaultConnection";
33 private readonly IDbConnection db ;
34 public Dapperr(IConfiguration config)
35 {
36 _config = config;
37 db = new SqlConnection(_config.GetConnectionString(Connectionstring));
38 }
39
40
41 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
42 {
43
44 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
45 }
46
47 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
48 {
49
50 return db.Query<T>(sp, parms, commandType: commandType).ToList();
51 }
52
53 }
54
does the sql connection dispose after request ended or I still need to use using
?
ANSWER
Answered 2022-Mar-29 at 09:28After reading the comments I got that, I have to set the the interface as IDisposable
to dispose the connection, so I changed my code like this:
1public class Dapperr : IDapper
2 {
3 private readonly IConfiguration _config;
4 private string Connectionstring = "DefaultConnection";
5
6 public Dapperr(IConfiguration config)
7 {
8 _config = config;
9 }
10 public void Dispose()
11 {
12
13 }
14
15
16 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
17 {
18 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
19 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
20 }
21
22 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
23 {
24 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
25 return db.Query<T>(sp, parms, commandType: commandType).ToList();
26 }
27}
28services.AddScoped<IDapper, Dapperr>();
29public class Dapperr : IDapper
30 {
31 private readonly IConfiguration _config;
32 private string Connectionstring = "DefaultConnection";
33 private readonly IDbConnection db ;
34 public Dapperr(IConfiguration config)
35 {
36 _config = config;
37 db = new SqlConnection(_config.GetConnectionString(Connectionstring));
38 }
39
40
41 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
42 {
43
44 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
45 }
46
47 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
48 {
49
50 return db.Query<T>(sp, parms, commandType: commandType).ToList();
51 }
52
53 }
54public interface IDapper : IDisposeable
55{
56 ...
57}
58
then in my repo, I implemented dispose method:
1public class Dapperr : IDapper
2 {
3 private readonly IConfiguration _config;
4 private string Connectionstring = "DefaultConnection";
5
6 public Dapperr(IConfiguration config)
7 {
8 _config = config;
9 }
10 public void Dispose()
11 {
12
13 }
14
15
16 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
17 {
18 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
19 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
20 }
21
22 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
23 {
24 using IDbConnection db = new SqlConnection(_config.GetConnectionString(Connectionstring));
25 return db.Query<T>(sp, parms, commandType: commandType).ToList();
26 }
27}
28services.AddScoped<IDapper, Dapperr>();
29public class Dapperr : IDapper
30 {
31 private readonly IConfiguration _config;
32 private string Connectionstring = "DefaultConnection";
33 private readonly IDbConnection db ;
34 public Dapperr(IConfiguration config)
35 {
36 _config = config;
37 db = new SqlConnection(_config.GetConnectionString(Connectionstring));
38 }
39
40
41 public T Get<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.Text)
42 {
43
44 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
45 }
46
47 public List<T> GetAll<T>(string sp, DynamicParameters parms, CommandType commandType = CommandType.StoredProcedure)
48 {
49
50 return db.Query<T>(sp, parms, commandType: commandType).ToList();
51 }
52
53 }
54public interface IDapper : IDisposeable
55{
56 ...
57}
58public class Dapperr : IDapper
59{
60 private readonly IConfiguration _config;
61 private string Connectionstring = "DefaultConnection";
62 private readonly IDbConnection db;
63
64 public Dapperr(IConfiguration config)
65 {
66 _config = config;
67 db = new SqlConnection(_config.GetConnectionString(Connectionstring));
68 }
69
70 public T Get<T>(
71 string sp,
72 DynamicParameters parms,
73 CommandType commandType = CommandType.Text)
74 {
75 return db.Query<T>(sp, parms, commandType: commandType).FirstOrDefault();
76 }
77
78 public List<T> GetAll<T>(string sp, DynamicParameters parms) =>
79 db.Query<T>(sp, parms, commandType: commandType).ToList();
80
81 public void Dispose()
82 {
83 db?.dispose();
84 }
85}
86
After debugging, I saw this Dispose
method is called and connection disposed. I'm not sure this is the best practice but by these changes I only wrote the connection config once and all my using
blocs deleted. I think this would be good for light requests.
QUESTION
How to use appsettings.json in Asp.net core 6 Program.cs file
Asked 2022-Feb-25 at 21:39I'm trying to access appsettings.json in my Asp.net core v6 application Program.cs file, but in this version of .Net the Startup class and Program class are merged together and the using and another statements are simplified and removed from Program.cs. In this situation, How to access IConfiguration or how to use dependency injection for example ?
Edited : Here is my default Program.cs that Asp.net 6 created for me
1var builder = WebApplication.CreateBuilder(args);
2// Add services to the container.
3builder.Services.AddControllers();
4builder.Services.AddStackExchangeRedisCache(options =>
5{
6 options.Configuration = "localhost:6379";
7});
8
9builder.Services.AddSwaggerGen(c =>
10{
11 c.SwaggerDoc("v1", new() { Title = "BasketAPI", Version = "v1" });
12});
13var app = builder.Build();
14// Configure the HTTP request pipeline.
15if (app.Environment.IsDevelopment())
16{
17 app.UseSwagger();
18 app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BasketAPI v1"));
19}
20app.UseHttpsRedirection();
21app.UseAuthorization();
22app.MapControllers();
23app.Run();
24
For example , I want to use appsettings.json instead of hard typed connectionstring in this line :
1var builder = WebApplication.CreateBuilder(args);
2// Add services to the container.
3builder.Services.AddControllers();
4builder.Services.AddStackExchangeRedisCache(options =>
5{
6 options.Configuration = "localhost:6379";
7});
8
9builder.Services.AddSwaggerGen(c =>
10{
11 c.SwaggerDoc("v1", new() { Title = "BasketAPI", Version = "v1" });
12});
13var app = builder.Build();
14// Configure the HTTP request pipeline.
15if (app.Environment.IsDevelopment())
16{
17 app.UseSwagger();
18 app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BasketAPI v1"));
19}
20app.UseHttpsRedirection();
21app.UseAuthorization();
22app.MapControllers();
23app.Run();
24options.Configuration = "localhost:6379";
25
ANSWER
Answered 2021-Sep-30 at 11:13Assuming an appsettings.json
1var builder = WebApplication.CreateBuilder(args);
2// Add services to the container.
3builder.Services.AddControllers();
4builder.Services.AddStackExchangeRedisCache(options =>
5{
6 options.Configuration = "localhost:6379";
7});
8
9builder.Services.AddSwaggerGen(c =>
10{
11 c.SwaggerDoc("v1", new() { Title = "BasketAPI", Version = "v1" });
12});
13var app = builder.Build();
14// Configure the HTTP request pipeline.
15if (app.Environment.IsDevelopment())
16{
17 app.UseSwagger();
18 app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BasketAPI v1"));
19}
20app.UseHttpsRedirection();
21app.UseAuthorization();
22app.MapControllers();
23app.Run();
24options.Configuration = "localhost:6379";
25{
26 "RedisCacheOptions" : {
27 "Configuration": "localhost:6379"
28 }
29}
30
There is nothing stopping you from building a configuration object to extract the desired settings.
1var builder = WebApplication.CreateBuilder(args);
2// Add services to the container.
3builder.Services.AddControllers();
4builder.Services.AddStackExchangeRedisCache(options =>
5{
6 options.Configuration = "localhost:6379";
7});
8
9builder.Services.AddSwaggerGen(c =>
10{
11 c.SwaggerDoc("v1", new() { Title = "BasketAPI", Version = "v1" });
12});
13var app = builder.Build();
14// Configure the HTTP request pipeline.
15if (app.Environment.IsDevelopment())
16{
17 app.UseSwagger();
18 app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BasketAPI v1"));
19}
20app.UseHttpsRedirection();
21app.UseAuthorization();
22app.MapControllers();
23app.Run();
24options.Configuration = "localhost:6379";
25{
26 "RedisCacheOptions" : {
27 "Configuration": "localhost:6379"
28 }
29}
30IConfiguration configuration = new ConfigurationBuilder()
31 .AddJsonFile("appsettings.json")
32 .Build();
33
34var builder = WebApplication.CreateBuilder(args);
35// Add services to the container.
36builder.Services.AddControllers();
37builder.Services.AddStackExchangeRedisCache(options => {
38 options.Configuration = configuration["RedisCacheOptions:Configuration"];
39});
40
41//...
42
QUESTION
Android Build Error: "lStar not found..."
Asked 2022-Feb-18 at 06:59I have error like this after trying to build my apps in Emulator
/Users/joel/.gradle/caches/transforms-3/06231cc1265260b25a06bafce7a4176f/transformed/core-1.7.0-alpha02/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.
I don't know what causes this error. After digging some answer which has similarly error (but in flutter) Problem. But still not solved my issue.
I have this dependency in my project
1buildscript {
2 repositories {
3 google()
4 maven { url 'https://plugins.gradle.org/m2/' }
5 }
6
7 dependencies {
8 classpath 'com.google.gms:google-services:4.3.3'
9 classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
10 }
11}
12apply plugin: 'com.android.application'
13apply plugin: 'com.google.gms.google-services'
14apply plugin: 'kotlin-android'
15apply plugin: 'kotlin-android-extensions'
16apply plugin: 'kotlin-kapt'
17apply plugin: 'com.google.firebase.crashlytics'
18
19repositories {
20 maven { url 'https://maven.fabric.io/public' }
21 maven { url 'https://maven.google.com' }
22 maven { url "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod"}
23 mavenCentral()
24
25}
26
27android {
28 compileSdkVersion 29
29 buildToolsVersion '28.0.3'
30 defaultConfig {
31 applicationId "mobile.apps.my"
32 minSdkVersion 17
33 targetSdkVersion 29
34 multiDexEnabled true
35 versionCode 152
36 versionName "8.1.7"
37 vectorDrawables.useSupportLibrary = true // This line hereP
38 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
39 }
40
41 compileOptions {
42 sourceCompatibility JavaVersion.VERSION_1_8
43 targetCompatibility JavaVersion.VERSION_1_8
44 }
45
46 dataBinding {
47 enabled = true
48 }
49
50 buildTypes {
51 debug {
52 firebaseCrashlytics {
53 mappingFileUploadEnabled false
54 }
55 }
56
57 release {
58 minifyEnabled true
59 shrinkResources true
60 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
61 }
62 }
63
64 lintOptions {
65 checkReleaseBuilds false
66 abortOnError false
67 }
68}
69
70dependencies {
71
72 implementation fileTree(include: ['*.jar'], dir: 'libs')
73 androidTestImplementation('androidx.test.espresso:espresso-core:3.2.0-beta01', {
74 exclude group: 'com.android.support', module: 'support-annotations'
75 })
76 //noinspection GradleCompatible
77 implementation 'androidx.appcompat:appcompat:1.4.0-alpha03'
78 implementation "androidx.appcompat:appcompat-resources:1.4.0-alpha03"
79
80 implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
81 implementation 'androidx.preference:preference:1.1.1'
82 implementation 'com.google.android.material:material:1.4.0'
83 implementation 'androidx.recyclerview:recyclerview:1.2.1'
84 implementation 'androidx.cardview:cardview:1.0.0'
85 implementation 'androidx.percentlayout:percentlayout:1.0.0'
86
87 implementation 'com.google.android.gms:play-services-analytics:17.0.0'
88 implementation 'it.sephiroth.android.library.imagezoom:imagezoom:2.3.0'
89 testImplementation 'org.json:json:20140107'
90 implementation 'com.comscore:android-analytics:6.1.0'
91 implementation 'com.android.support:customtabs:29.0.0'
92 implementation 'androidx.viewpager2:viewpager2:1.0.0'
93 implementation 'com.android.support:customtabs:29.0.0'
94
95 // Kodein Dependency Injection
96 implementation 'org.kodein.di:kodein-di-generic-jvm:6.2.1'
97 implementation 'org.kodein.di:kodein-di-framework-android-x:6.2.1'
98
99 // RETROFIT
100 implementation 'com.squareup.retrofit2:retrofit:2.6.0'
101 implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
102 implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
103 implementation 'com.google.code.gson:gson:2.8.5'
104 implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' // for test String
105
106
107 // Room components
108 implementation "androidx.room:room-runtime:2.2.5"
109 kapt "androidx.room:room-compiler:2.2.5"
110 implementation "androidx.room:room-ktx:2.2.5"
111 androidTestImplementation "androidx.room:room-testing:2.2.5"
112
113 // Lifecycle components
114 implementation 'android.arch.lifecycle:extensions:1.1.1'
115 implementation 'androidx.paging:paging-runtime:2.1.2'
116
117 // UI
118 implementation 'com.squareup.picasso:picasso:2.71828'
119 implementation 'com.geniusforapp.fancydialog:FancyDialog:0.1.4'
120 implementation 'com.github.bluzwong:swipeback:0.2.0@aar'
121 implementation 'com.airbnb.android:lottie:3.6.0'
122
123 implementation 'com.veinhorn.scrollgalleryview:library:1.2.6'
124 implementation 'com.veinhorn.scrollgalleryview:picasso-loader:1.2.4'
125 implementation 'com.github.rubensousa:bottomsheetbuilder:1.6.1'
126 implementation "com.andkulikov:transitionseverywhere:1.8.1"
127
128
129 // HTTP LOGGING
130 implementation 'com.jakewharton.timber:timber:4.7.1'
131 implementation 'org.jsoup:jsoup:1.13.1'
132 implementation 'androidx.multidex:multidex:2.0.1'
133
134
135 // ADS
136 implementation 'com.android.support:support-annotations:28.0.0'
137 // Required Dependency by Audience Network SDK
138 implementation 'com.google.android.gms:play-services-ads:19.7.0'
139 implementation 'com.google.android.gms:play-services-basement:17.6.0'
140 implementation("tv.teads.sdk.android:sdk:4.7.2@aar") {
141 transitive = true
142 }
143 implementation 'com.criteo.publisher:criteo-publisher-sdk:4.0.0'
144 implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
145 implementation 'com.google.android.gms:play-services-base:17.6.0'
146
147 implementation ('com.facebook.android:audience-network-sdk:5.5.0'){
148 exclude group: 'com.google.android.gms'
149 }
150
151 implementation 'com.google.firebase:firebase-crashlytics:17.4.0'
152
153 implementation "androidx.core:core-ktx:1.6.0" // I have update this based on other solution
154 implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
155 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
156
157 // COROUTINES
158 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
159 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
160 implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
161
162 // Kotlin + coroutines
163 implementation "androidx.work:work-runtime-ktx:2.5.0"
164
165 implementation 'com.github.mumayank:AirLocation:1.3.1'
166 androidTestImplementation 'androidx.test:rules:1.3.0-beta01'
167
168 implementation 'com.android.installreferrer:installreferrer:2.2'
169
170 //ANIMATION
171 implementation 'com.daimajia.androidanimations:library:2.4@aar'
172 implementation 'com.infideap.drawerbehavior:drawer-behavior:1.0.4'
173 implementation 'com.romandanylyk:pageindicatorview:1.0.3'
174
175 implementation 'org.ocpsoft.prettytime:prettytime:5.0.0.Final'
176
177 //SOCIAL
178 implementation 'com.google.android.gms:play-services-auth:19.0.0'
179
180}
181
I have tried to upgrade version of androidx.core:core-ktx:1.6.0
then sync or invalidate cache/restart. But none of them give me good result. I am sure yesterday my project was alright with same dependency. Someone please help me, if this question unclear let me add more information. Thanks
ANSWER
Answered 2021-Sep-28 at 17:18I managed to fix this by upgrading compileSdk to 31 and kotlin gradle plugin to 1.5.10
1buildscript {
2 repositories {
3 google()
4 maven { url 'https://plugins.gradle.org/m2/' }
5 }
6
7 dependencies {
8 classpath 'com.google.gms:google-services:4.3.3'
9 classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
10 }
11}
12apply plugin: 'com.android.application'
13apply plugin: 'com.google.gms.google-services'
14apply plugin: 'kotlin-android'
15apply plugin: 'kotlin-android-extensions'
16apply plugin: 'kotlin-kapt'
17apply plugin: 'com.google.firebase.crashlytics'
18
19repositories {
20 maven { url 'https://maven.fabric.io/public' }
21 maven { url 'https://maven.google.com' }
22 maven { url "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod"}
23 mavenCentral()
24
25}
26
27android {
28 compileSdkVersion 29
29 buildToolsVersion '28.0.3'
30 defaultConfig {
31 applicationId "mobile.apps.my"
32 minSdkVersion 17
33 targetSdkVersion 29
34 multiDexEnabled true
35 versionCode 152
36 versionName "8.1.7"
37 vectorDrawables.useSupportLibrary = true // This line hereP
38 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
39 }
40
41 compileOptions {
42 sourceCompatibility JavaVersion.VERSION_1_8
43 targetCompatibility JavaVersion.VERSION_1_8
44 }
45
46 dataBinding {
47 enabled = true
48 }
49
50 buildTypes {
51 debug {
52 firebaseCrashlytics {
53 mappingFileUploadEnabled false
54 }
55 }
56
57 release {
58 minifyEnabled true
59 shrinkResources true
60 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
61 }
62 }
63
64 lintOptions {
65 checkReleaseBuilds false
66 abortOnError false
67 }
68}
69
70dependencies {
71
72 implementation fileTree(include: ['*.jar'], dir: 'libs')
73 androidTestImplementation('androidx.test.espresso:espresso-core:3.2.0-beta01', {
74 exclude group: 'com.android.support', module: 'support-annotations'
75 })
76 //noinspection GradleCompatible
77 implementation 'androidx.appcompat:appcompat:1.4.0-alpha03'
78 implementation "androidx.appcompat:appcompat-resources:1.4.0-alpha03"
79
80 implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
81 implementation 'androidx.preference:preference:1.1.1'
82 implementation 'com.google.android.material:material:1.4.0'
83 implementation 'androidx.recyclerview:recyclerview:1.2.1'
84 implementation 'androidx.cardview:cardview:1.0.0'
85 implementation 'androidx.percentlayout:percentlayout:1.0.0'
86
87 implementation 'com.google.android.gms:play-services-analytics:17.0.0'
88 implementation 'it.sephiroth.android.library.imagezoom:imagezoom:2.3.0'
89 testImplementation 'org.json:json:20140107'
90 implementation 'com.comscore:android-analytics:6.1.0'
91 implementation 'com.android.support:customtabs:29.0.0'
92 implementation 'androidx.viewpager2:viewpager2:1.0.0'
93 implementation 'com.android.support:customtabs:29.0.0'
94
95 // Kodein Dependency Injection
96 implementation 'org.kodein.di:kodein-di-generic-jvm:6.2.1'
97 implementation 'org.kodein.di:kodein-di-framework-android-x:6.2.1'
98
99 // RETROFIT
100 implementation 'com.squareup.retrofit2:retrofit:2.6.0'
101 implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
102 implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
103 implementation 'com.google.code.gson:gson:2.8.5'
104 implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' // for test String
105
106
107 // Room components
108 implementation "androidx.room:room-runtime:2.2.5"
109 kapt "androidx.room:room-compiler:2.2.5"
110 implementation "androidx.room:room-ktx:2.2.5"
111 androidTestImplementation "androidx.room:room-testing:2.2.5"
112
113 // Lifecycle components
114 implementation 'android.arch.lifecycle:extensions:1.1.1'
115 implementation 'androidx.paging:paging-runtime:2.1.2'
116
117 // UI
118 implementation 'com.squareup.picasso:picasso:2.71828'
119 implementation 'com.geniusforapp.fancydialog:FancyDialog:0.1.4'
120 implementation 'com.github.bluzwong:swipeback:0.2.0@aar'
121 implementation 'com.airbnb.android:lottie:3.6.0'
122
123 implementation 'com.veinhorn.scrollgalleryview:library:1.2.6'
124 implementation 'com.veinhorn.scrollgalleryview:picasso-loader:1.2.4'
125 implementation 'com.github.rubensousa:bottomsheetbuilder:1.6.1'
126 implementation "com.andkulikov:transitionseverywhere:1.8.1"
127
128
129 // HTTP LOGGING
130 implementation 'com.jakewharton.timber:timber:4.7.1'
131 implementation 'org.jsoup:jsoup:1.13.1'
132 implementation 'androidx.multidex:multidex:2.0.1'
133
134
135 // ADS
136 implementation 'com.android.support:support-annotations:28.0.0'
137 // Required Dependency by Audience Network SDK
138 implementation 'com.google.android.gms:play-services-ads:19.7.0'
139 implementation 'com.google.android.gms:play-services-basement:17.6.0'
140 implementation("tv.teads.sdk.android:sdk:4.7.2@aar") {
141 transitive = true
142 }
143 implementation 'com.criteo.publisher:criteo-publisher-sdk:4.0.0'
144 implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
145 implementation 'com.google.android.gms:play-services-base:17.6.0'
146
147 implementation ('com.facebook.android:audience-network-sdk:5.5.0'){
148 exclude group: 'com.google.android.gms'
149 }
150
151 implementation 'com.google.firebase:firebase-crashlytics:17.4.0'
152
153 implementation "androidx.core:core-ktx:1.6.0" // I have update this based on other solution
154 implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
155 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
156
157 // COROUTINES
158 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
159 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
160 implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
161
162 // Kotlin + coroutines
163 implementation "androidx.work:work-runtime-ktx:2.5.0"
164
165 implementation 'com.github.mumayank:AirLocation:1.3.1'
166 androidTestImplementation 'androidx.test:rules:1.3.0-beta01'
167
168 implementation 'com.android.installreferrer:installreferrer:2.2'
169
170 //ANIMATION
171 implementation 'com.daimajia.androidanimations:library:2.4@aar'
172 implementation 'com.infideap.drawerbehavior:drawer-behavior:1.0.4'
173 implementation 'com.romandanylyk:pageindicatorview:1.0.3'
174
175 implementation 'org.ocpsoft.prettytime:prettytime:5.0.0.Final'
176
177 //SOCIAL
178 implementation 'com.google.android.gms:play-services-auth:19.0.0'
179
180}
181compileSdk = 31
182
183classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10'
184
QUESTION
How to register ServiceBusClient for dependency injection?
Asked 2022-Feb-08 at 14:11I’m trying to register ServiceBusClient
from the new Azure.Messaging.ServiceBus package for dependency injection as recommended in this article using ServiceBusClientBuilderExtensions
, but I can’t find any documentation or any help online on how exactly to go about this.
I'm trying to add as below
1public override void Configure(IFunctionsHostBuilder builder)
2{
3 ServiceBusClientBuilderExtensions.AddServiceBusClient(builder, Typsy.Domain.Configuration.Settings.Instance().Connections.ServiceBusPrimary);
4}
5
but I'm getting the error
The type 'Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder' must be convertible to 'Azure.Core.Extensions.IAzureClientFactoryBuilder' in order to use it as parameter 'TBuilder' in the generic method 'IAzureClientBuilder<ServiceBusClient,ServiceBusClientOptions> Microsoft.Extensions.Azure.ServiceBusClientBuilderExtensions.AddServiceBusClient(this TBuilder, string)'
If anyone can help with this that'll be great!
ANSWER
Answered 2021-Sep-02 at 20:03ServiceBusClientBuilderExtensions.AddServiceBusClient
is an extension method of IAzureClientFactoryBuilder
:
1public override void Configure(IFunctionsHostBuilder builder)
2{
3 ServiceBusClientBuilderExtensions.AddServiceBusClient(builder, Typsy.Domain.Configuration.Settings.Instance().Connections.ServiceBusPrimary);
4}
5public static IAzureClientBuilder<ServiceBusClient, ServiceBusClientOptions> AddServiceBusClient<TBuilder>(this TBuilder builder, string connectionString)
6 where TBuilder : IAzureClientFactoryBuilder
7
To get an instance of IAzureClientFactoryBuilder
, you need to call AzureClientServiceCollectionExtensions.AddAzureClients(IServiceCollection, Action<AzureClientFactoryBuilder>)
for a given IServiceCollection
, which provides a delegate giving an instance of IAzureClientFactoryBuilder
. (this method is in the Microsoft.Extensions.Azure
NuGet package)
To call that method, you can use the IServiceCollection
provided by IFunctionsHostBuilder
. With all of that, what you have should look something like:
1public override void Configure(IFunctionsHostBuilder builder)
2{
3 ServiceBusClientBuilderExtensions.AddServiceBusClient(builder, Typsy.Domain.Configuration.Settings.Instance().Connections.ServiceBusPrimary);
4}
5public static IAzureClientBuilder<ServiceBusClient, ServiceBusClientOptions> AddServiceBusClient<TBuilder>(this TBuilder builder, string connectionString)
6 where TBuilder : IAzureClientFactoryBuilder
7public override void Configure(IFunctionsHostBuilder builder)
8{
9 builder.Services.AddAzureClients(clientsBuilder =>
10 {
11 clientsBuilder.AddServiceBusClient(Typsy.Domain.Configuration.Settings.Instance().Connections.ServiceBusPrimary)
12 // (Optional) Provide name for instance to retrieve by with DI
13 .WithName("Client1Name")
14 // (Optional) Override ServiceBusClientOptions (e.g. change retry settings)
15 .ConfigureOptions(options =>
16 {
17 options.RetryOptions.Delay = TimeSpan.FromMilliseconds(50);
18 options.RetryOptions.MaxDelay = TimeSpan.FromSeconds(5);
19 options.RetryOptions.MaxRetries = 3;
20 });
21 });
22}
23
To retrieve the named instance, instead of using ServiceBusClient
as the injected type you use IAzureClientFactory<ServiceBusClient>
. The ServiceBusClient
is a Singleton regardless of whether you use a named instance or not.
1public override void Configure(IFunctionsHostBuilder builder)
2{
3 ServiceBusClientBuilderExtensions.AddServiceBusClient(builder, Typsy.Domain.Configuration.Settings.Instance().Connections.ServiceBusPrimary);
4}
5public static IAzureClientBuilder<ServiceBusClient, ServiceBusClientOptions> AddServiceBusClient<TBuilder>(this TBuilder builder, string connectionString)
6 where TBuilder : IAzureClientFactoryBuilder
7public override void Configure(IFunctionsHostBuilder builder)
8{
9 builder.Services.AddAzureClients(clientsBuilder =>
10 {
11 clientsBuilder.AddServiceBusClient(Typsy.Domain.Configuration.Settings.Instance().Connections.ServiceBusPrimary)
12 // (Optional) Provide name for instance to retrieve by with DI
13 .WithName("Client1Name")
14 // (Optional) Override ServiceBusClientOptions (e.g. change retry settings)
15 .ConfigureOptions(options =>
16 {
17 options.RetryOptions.Delay = TimeSpan.FromMilliseconds(50);
18 options.RetryOptions.MaxDelay = TimeSpan.FromSeconds(5);
19 options.RetryOptions.MaxRetries = 3;
20 });
21 });
22}
23 public Constructor(IAzureClientFactory<ServiceBusClient> serviceBusClientFactory)
24 {
25 // Wherever you need the ServiceBusClient
26 ServiceBusClient singletonClient1 = serviceBusClientFactory.CreateClient("Client1Name")
27 }
28
QUESTION
How to create beans dynamically using a DI framework
Asked 2022-Jan-22 at 11:44requirement is like this: user input is single character followed by an array of integers, such as 'A 1 2', 'B 3 4 5', 'C 1', etc. The single character means which class to construct and integers are input parameter to that constructor. Please note different classes might need different number of integers.
Then we need to write a program to parse user input and create objects accordingly.
My approach was to use regular expression for parsing and hard code which class to call.
But another senior developer said a better idea would be using dependency injection to automatically create objects based on user input. He gave another hint to create an interface and use spring framework dependency injection (not spring boot).
I am still confused how to create beans dynamically in this way. Can anybody help please?
ANSWER
Answered 2022-Jan-22 at 11:44You can create a common interface for the classes that can be created, and a Factory bean that transforms the input.
1// common interface
2interface MyObject {
3 void someMethod();
4}
5class A implements MyObject {
6 public A(List<Integer> params) { ... }
7}
8class B implements MyObject {
9 public B(List<Integer> params) { ... }
10}
11
12// parsed data
13class Input {
14 char character;
15 List<Integer> ints;
16 // getters, setters
17}
18interface MyObjectFactory {
19 public MyObject apply(Input input);
20}
21
22@Bean
23class MyObjectFactory implements MyObjectFactory {
24 public MyObject apply(Input input) {
25 // create object from input, eg switch over input.getCharacter()
26 };
27}
28// injected
29class MyClientService {
30 @Autowired
31 MyObjectFactory objectFactory;
32
33 public void doStuff() {
34 List<Input> parsedInputs = parse(something);
35 for (Input input : parsedInputs) {
36 MyObject object = objectFactory.apply(input);
37 // ...
38 }
39 }
40}
41
QUESTION
What is the difference between static class and singleton in .net mvc project?
Asked 2022-Jan-16 at 10:42I understand difference between static class and singleton, importantly that singleton can be instantiated once where as static class doesn't need an instance.
This question is with the perspective of a .net mvc project, to help me make decision between using either of them.
So assuming I have Class(es) with methods like the examples given below:
I have a method like
ConvertMeterToMiles(int mtr)
, where there is no dependency injected.Or a method like
SendEmail(str eaddress)
, where there is no dependency injected but it instantiatesnew SMTPClient...
followed by disposing the SMTPClient in the finally
Assuming I want to put the method into utility service class, then should I create a static class or singleton (ofcource with dependency injection)?
I understand there is no point of scoped or transient because there is no benefit to have new instances.
ANSWER
Answered 2022-Jan-05 at 15:21Adding a singleton via dependency injection instantiates an instance of the requested class. A static class cannot be instantiated, and so you simply access its methods from elsewhere, based on the static class's access modifiers.
QUESTION
.NET Core Dependency Injection how to handle multiple objects
Asked 2021-Dec-29 at 06:56As the title says I have a .NET Core application that I am trying to convert over to and take advantage of the built in Microsoft Dependency Injection.
I have an object and a base class for the object, call it CommunicationBase
and Communicator
. When my app starts up and reads the configuration file, I can have N number of objects to instantiate.
Previously, before switching to Dependency Injection, somewhere in my startup routine, where I read the configuration file, I would have a List<CommunicationBase>
variable that I would instantiate and add Communicator
objects to and at the same time, set some of the base properties, which changed based on how many were in my configuration and each ones properties in config.
How would I achieve this with DI?
I understand that in my services, I would register the type so it can be injected into other class constructors.
For example, services.AddTransient<CommunicationBase, Communicator>();
but as I understand it, this just registers the types with DI. I can inject it into a class and have a random instance of one of them.
How would I then have N number of instances and be able to set properties of each one as I create the instance?
Or, is this a scenario where DI is not necessary or won't work and I need to just do it the way I was doing it before?
Thanks!
ANSWER
Answered 2021-Dec-28 at 11:26Firstly do you need to has clear the differences between Transient, Scoped, Singleton lifetime. To understand how works with the list of Communicator objects that will be read from your configuration file.
One approuch to resolve your question is
- Create an interface ICommunicatorList with one method to get a List, i mean you can envolve the list of communicators.
- Create a clase that inherits from ICommunicatorList (for example called CommunicatorList), with a private field for your list of Communicators. On the constructor method set your private field with the list of communicator, o here you can receive like a parameter from the section of the config file to iterate and full your private field.
- on this class implement your code to return the list of communicators.
- Now, in your startups file you can now create the service services.AddTransient< ICommunicatorList>(x => new CommunicatorList(parameters));
QUESTION
Does using Spring boot with javafx will consume a lot of memory?
Asked 2021-Dec-24 at 07:25I'm willing to use Spring boot technology in my JavaFX application (to get the advantage of its dependency injection), but I'm wondering about the consequences on the memory, as you know any class with a "component" notation will be loaded to the MetaSpace (since it Spring boot will create a static object from it), so with tens of JavaFx view controllers loaded to the MetaSpace they will never get garbage collected from the launching of the application to the end, which is obviously a bad thing, is there any way to get around of this issue?
ANSWER
Answered 2021-Dec-24 at 07:25You write in comments:
JavaFX applications when the view controller doesn't get garbage collected means also the view objects will always stay there TableViews,ListViews,Panes ... which may take some important space
But I don’t think it needs to be that way.
The controller instance which references the Java nodes is just a Java object like any other and will be available for garbage collection when there are no more references to it in the JVM.
Let’s say you configure your JavaFX SpringBoot integration like this:
So you configure your controller factory to use Spring beans:
1fxmlLoader.setControllerFactory(
2 springContext::getBean
3);
4
Then your controllers are Spring beans whose scope you can control.
If you use prototype scope:
1fxmlLoader.setControllerFactory(
2 springContext::getBean
3);
4@Bean
5@Scope("prototype")
6public PersonController personControllerPrototype() {
7 return new PersonController();
8}
9
Then the behavior is as specified in:
Spring does not manage the complete lifecycle of a prototype bean: the container instantiates, configures, and otherwise assembles a prototype object, and hands it to the client, with no further record of that prototype instance.
Typically you will create a controller and add a reference to the object tree that it instantiates into the scene graph. If you replace the tree in the scene graph when you navigate, and you don’t keep a reference to the controller anywhere, then the controller and any other associated nodes which have been removed from the scene graph can be garbage collected.
Or, if you wanted to just load the fxml once and keep the controller around forever you could use singleton scope to do that.
So basically, you can choose the scope and lifecycle of your controllers to be as best fits your application or the individual controllers that you are using.
QUESTION
.Net 6 Console app: WebApplication.CreateBuilder vs Host.CreateDefaultBuilder
Asked 2021-Dec-14 at 08:36I'm looking into .NET 6, and wanted to build a simple console application, with some dependency injection.
From what i can read, a lot has been done to make the startup (now just program) file, more readable. What does confuse me a bit is, that all improvements seems to have been made to WebApplication.CreateBuilderpart used in API projects, and not the Host.CreateDefaultBuilder. As mentioned in this blog
Microsofts own docs, also only seems to mention WebApplication.
To me it seems like WebApplication is only for web projects, like an API, and i can't find anything that confirms og debunks that.
Is it okay to use WebApplication in a console application, or should i rely on Host, and keep the stacked lambda expressions ?
ANSWER
Answered 2021-Dec-14 at 08:36WebApplication.CreateBuilderpart()
is only used for web/api applications like the name implies Host.CreateDefaultBuilder()
is used to build a generic host (without web services, middleware etc) which you can use to build anything other than webhost.
See for example; https://docs.microsoft.com/en-us/dotnet/core/extensions/generic-host Which has not changed.
Its true that it feels a bit awkward to build console apps and/or backgroundservices at the moment.
QUESTION
Android Instrumented tests with KodeIn
Asked 2021-Nov-30 at 16:26We have an Android app that is using compose for the view layer and we are using Kodein for all of our dependency injections.
I have a BaseApplication class which is DIAware:
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6
I also have a MainActivity and a nav graph to manage navigation between the various composables.
Problem: How can I properly override these modules in my instrumented tests for MainActivity?
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6@RunWith(AndroidJUnit4::class)
7class MainActivityTest {
8 @get:Rule
9 val composeTestRule = createAndroidComposeRule<MainActivity>()
10
11 val moduleOverrides = DI.Module(allowSilentOverride = true) {
12 // add bindings for fakes w/ allowOverride = true
13 }
14
15 @Before
16 fun setup() {
17 val application =
18 ApplicationProvider.getApplicationContext() as BaseApplication
19
20 // how can I override the BaseApplication modules for my test?
21 }
22
23}
24
I cant seem to find any clear language on the matter and feel like I am missing something very obvious. Any help would be very much appreciated.
ANSWER
Answered 2021-Nov-30 at 16:26There are several ways to achieve that. The general approach is to override the actual modules like
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6@RunWith(AndroidJUnit4::class)
7class MainActivityTest {
8 @get:Rule
9 val composeTestRule = createAndroidComposeRule<MainActivity>()
10
11 val moduleOverrides = DI.Module(allowSilentOverride = true) {
12 // add bindings for fakes w/ allowOverride = true
13 }
14
15 @Before
16 fun setup() {
17 val application =
18 ApplicationProvider.getApplicationContext() as BaseApplication
19
20 // how can I override the BaseApplication modules for my test?
21 }
22
23}
24val someParrentKodeinModule...
25
26val mockModule = Kodein {
27 extend(someParrentKodeinModule, allowOverride = true)
28 bind<Foo>(overrides = true) with provider { Foo2() }
29}
30
31or
32
33val kodein = Kodein {
34 /* ... */
35 import(testsModule, allowOverride = true)
36}
37
where testsModule
is some module that already defines all the needed mock components that will be overridden in the main one.
Your approach is also good. The key point is to replace your DI with the needed one - this can be done making the DI in your app - var
instead of val
and assigning new value to it. But you will have to drop DIAware
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6@RunWith(AndroidJUnit4::class)
7class MainActivityTest {
8 @get:Rule
9 val composeTestRule = createAndroidComposeRule<MainActivity>()
10
11 val moduleOverrides = DI.Module(allowSilentOverride = true) {
12 // add bindings for fakes w/ allowOverride = true
13 }
14
15 @Before
16 fun setup() {
17 val application =
18 ApplicationProvider.getApplicationContext() as BaseApplication
19
20 // how can I override the BaseApplication modules for my test?
21 }
22
23}
24val someParrentKodeinModule...
25
26val mockModule = Kodein {
27 extend(someParrentKodeinModule, allowOverride = true)
28 bind<Foo>(overrides = true) with provider { Foo2() }
29}
30
31or
32
33val kodein = Kodein {
34 /* ... */
35 import(testsModule, allowOverride = true)
36}
37class BaseApplication : Application() {
38 var di: DI = DI.lazy {
39 import(modules) // modules defined in respective packages
40 }
41}
42
43@Before
44 fun setup() {
45 val application =
46 ApplicationProvider.getApplicationContext() as BaseApplication
47
48 application.di = moduleOverrides
49 }
50
51
Something like that.
And generally using single DI for the app inside the App class is not recommended. Use specialized modules for each component of the app you want to test
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Dependency Injection
Tutorials and Learning Resources are not available at this moment for Dependency Injection