dependency-injection

Custom Json Converter with dependecy

时光怂恿深爱的人放手 提交于 2020-01-03 03:56:06
问题 I have to use a custom JsonConverter with ASP.NET Core for a reason, and I need to use it with JsonInputFormatter . The only way I've found is to use AddJsonOption extension method like this: services .AddMvc() .AddJsonOptions(jso => jso.SerializerSettings.Converters.Add(new CustomConverter())) But it has a flaw: CustomConverter requires a dependency from a DI container which cannot be easily solved at configuration time. So the question: is there any programmer friendly way to supply a

Plugin Architecture/Dependency Injection Question

ⅰ亾dé卋堺 提交于 2020-01-03 03:10:28
问题 I'm trying to figure out an architecture for plugins, but I've never worked with that. Essentially, my Program supports multiple database backends, but only one at a time. my idea was now to create a new Assembly (".DataCore") that contains all my Repository Interfaces (IFooRepository, IBarRepository) and a IDataPlugin Interface. Then, the Plugins have to implement all those interfaces. The user specifies the Name of the desired Assembly in the app.config file. My Program will then call a

Re-implementing WindowManager using ModernUI + Caliburn.Micro combination

萝らか妹 提交于 2020-01-03 02:23:14
问题 Here Caliburn.Micro was successfully combined with ModernUI. But if we want to use multiple windows we also need to re-implement Caliburn's WindowManager to work properly with ModernUI. How can it be done? UPDATE: (Additional question about IoC-Container/Dependency Injection) Ok, as I get it: I used a Constructor Injection here: public class BuildingsViewModel : Conductor<IScreen> { public BuildingsViewModel(IWindowManager _windowManager) { windowManager = _windowManager; } } As far as

Need help implementing Command Handlers/Bus using Unity DI

时间秒杀一切 提交于 2020-01-03 02:04:17
问题 Folks, I am trying to re-factor a legacy brownfield application into a CQRS architecture with commands and a command bus for domain modifications. The application will more than likely be implemented in Asp.Net MVC3. My employer prefers the use of Unity for DI in MVC applications. Any examples I can find showing a dependency container for command/bus resolution are based on Structuremap or Autofac, however I will need to use Unity in this implementation. Has anyone used Unity in this manner

.Net core DI Scope validation , scoped vs transient?

别等时光非礼了梦想. 提交于 2020-01-03 01:52:12
问题 Reading the docs : When the app is running in the Development environment, the default service provider performs checks to verify that: Scoped services aren't directly or indirectly resolved from the root service provider. Scoped services aren't directly or indirectly injected into singletons This means that I shouldn't inject Scoped services into a singleton service. Based on the fact that transient services creates an instance each time they're requested, VS scoped services which are single

How can I inject a property only if the value is non-null at runtime using Unity?

独自空忆成欢 提交于 2020-01-03 01:43:27
问题 I have an interface to resolve and one of the mapped object's dependencies has a property on it which I would like to set with a value that I only have available when I resolve the top level object. There's no valid default value for the property. If its not set it should be null and it should only be set if the value that I have available at resolve time is not null. Is this conditional property injection possible? I tried this... container.RegisterType<ProductInstanceValidatorBase,

How to inject a “runtime” dependency like a logged in user which is not available at application boot time?

大兔子大兔子 提交于 2020-01-02 22:18:13
问题 I'm just not getting this: I use Gin in my java GWT app to do DI. The login screen is integrated into the full application window. After the user has logged in I want to inject the user object into other classes like GUI Presenters which I create, so I have some sort of runtime dependency I believe. How do i do that? One solution I can think of is sth like: class Presenter { @Inject Presenter(LoggedInUserFactory userFactory) { User user = userFactory.getLoggedInUser(); } } class

How to use .net core dependency injection in multiprojects solution?

不打扰是莪最后的温柔 提交于 2020-01-02 15:14:49
问题 I'm new to asp.net core. What I'm trying to do is to build multi projects solution and use dependency injection to pass interfaces between projects. What I know is that in ASP.NET core project we have ConfigureServices method in startup.cs file to register our interfaces and their implementations like this: public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddTransient<IMyInterface,MyImplementation>(); ..... } This is good if

Simple Injector: Different DbContext for selected controllers

二次信任 提交于 2020-01-02 14:29:22
问题 I am trying to separate reads/writes in my MVC application. I am using Simple Injector as Ioc and I have following structure: new Service( new Repository( new UnitOfWork( new DbContext()))) So UnitOfWork registered per web request all the rest Transient . So idea was to create separate read-only controllers and make a registration of DbContext to supply a different connection if controller is read-only. And that could be achievable with improved RegisterWithContext extension BUT it will not

lombok and guice injection

荒凉一梦 提交于 2020-01-02 09:52:48
问题 I'm new to lombok and guice injection, I could get the general concept but I ran into some code which I don't understand and can't search due to the syntax. Following is the code, can someone help me understand this? import com.google.inject.Inject; import lombok.AccessLevel; import lombok.AllArgsConstructor; @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__({ @Inject })) public class SomeClass { ... } Thanks! 回答1: This is going to add a constructor with all fields as