dependency-injection

How to I access the DbContext of EF core from another project when used in ASP.NET core?

走远了吗. 提交于 2020-03-02 12:28:28
问题 I followed the pattern to use EF Core with ASP.NET core and all is well. But recently I created a 'Calculation' project and want to make database calls from it. The problem is I don't know how to create a new DbContextOptions . In my code that is done with services.AddDbContext<RetContext>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); But in a new .NET core class I need to provide it manually. How do I do this ? My code is

How to I access the DbContext of EF core from another project when used in ASP.NET core?

风格不统一 提交于 2020-03-02 12:27:31
问题 I followed the pattern to use EF Core with ASP.NET core and all is well. But recently I created a 'Calculation' project and want to make database calls from it. The problem is I don't know how to create a new DbContextOptions . In my code that is done with services.AddDbContext<RetContext>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); But in a new .NET core class I need to provide it manually. How do I do this ? My code is

How to I access the DbContext of EF core from another project when used in ASP.NET core?

时光毁灭记忆、已成空白 提交于 2020-03-02 12:27:12
问题 I followed the pattern to use EF Core with ASP.NET core and all is well. But recently I created a 'Calculation' project and want to make database calls from it. The problem is I don't know how to create a new DbContextOptions . In my code that is done with services.AddDbContext<RetContext>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); But in a new .NET core class I need to provide it manually. How do I do this ? My code is

Inject ViewModel using Dagger 2 + Kotlin + ViewModel

假如想象 提交于 2020-02-27 04:36:45
问题 class SlideshowViewModel : ViewModel() { @Inject lateinit var mediaItemRepository : MediaItemRepository fun init() { What goes here? } So I'm trying to learn Dagger2 so I can make my apps more testable. Problem is, I've already integrated Kotlin and am working on the Android Architectural components. I understand that constructor injection is preferable but this isn't possible with ViewModel . Instead, I can use lateinit in order to inject but I'm at a loss to figure out how to inject. Do I

How to register typed httpClient service with autofac?

蹲街弑〆低调 提交于 2020-02-25 04:49:46
问题 I'm creating MVC web application which calls an api using .net core 2.2 using separate HttpClient s to call each controller (same api). Ex: For user controller actions : UserService (httpclient) For post controller actions : PostService (httpclient) In startup.cs I use DI as: services.AddHttpClient<IUserService, UserService>(); services.AddHttpClient<IPostService, PostService>(); In my handler : public class CommandHandler : IRequestHandler<Command, BaseResponse> { private readonly

How to register typed httpClient service with autofac?

梦想与她 提交于 2020-02-25 04:49:10
问题 I'm creating MVC web application which calls an api using .net core 2.2 using separate HttpClient s to call each controller (same api). Ex: For user controller actions : UserService (httpclient) For post controller actions : PostService (httpclient) In startup.cs I use DI as: services.AddHttpClient<IUserService, UserService>(); services.AddHttpClient<IPostService, PostService>(); In my handler : public class CommandHandler : IRequestHandler<Command, BaseResponse> { private readonly

Differences and similarities between: ViewModelLocator, ServiceLocator, Dependency Injection

好久不见. 提交于 2020-02-25 02:13:01
问题 I'm confused about the patterns: ViewModelLocator , ServiceLocator , Dependency Injection . The latest conclusion are as follows: ViewModelLocator . The place to connect View and ViewModel . public ViewModelLocator() { SimpleIoc.Default.Register<MainViewModel>(); SimpleIoc.Default.Register<SettingViewModel>(); } public MainViewModel MainViewModel => SimpleIoc.Default.GetInstance<MainViewModel>(); public SettingViewModel SettingViewModel => SimpleIoc.Default.GetInstance<SettingViewModel>(); //

Spring Lookup Method Injection failing with AbstractMethodError

醉酒当歌 提交于 2020-02-23 06:54:48
问题 I have a singleton service class like the below. @Service public class SingletonClass{ @Autowired private ContextProvider provider; public Context run(){ context = provider.createContext(); updateContext(context) } ContextProvider class: public abstract class ContextProvider implements MyInterface{ public abstract Context createContext(); } configuration: <bean name="provider" class="xyz.s.s.ContextProvider" > <lookup-method name="createContext" bean="someBean" /> </bean> <bean id="somebean"

Polymorphism and dependency injection - too many dependencies

拜拜、爱过 提交于 2020-02-08 02:35:02
问题 So I have read that if we see a switch statement, its a sign that it needs polymorphism. I saw such polymorphism example: include 'vendor/autoload.php'; $calc = new Calculator(); $calc->setOperands(5, 6); $calc->setOperation(new Addition); echo $result = $calc->calculate(); And of course there can be various classes as Subtract, Multiply, Root, etc. Now lets say I want to use this code in a Laravel framework, but this I think should apply to any php framework. Example of addition class ( same

Polymorphism and dependency injection - too many dependencies

柔情痞子 提交于 2020-02-08 02:34:09
问题 So I have read that if we see a switch statement, its a sign that it needs polymorphism. I saw such polymorphism example: include 'vendor/autoload.php'; $calc = new Calculator(); $calc->setOperands(5, 6); $calc->setOperation(new Addition); echo $result = $calc->calculate(); And of course there can be various classes as Subtract, Multiply, Root, etc. Now lets say I want to use this code in a Laravel framework, but this I think should apply to any php framework. Example of addition class ( same