dependency-injection

Using Dependency Injection in .NET Core Service application

元气小坏坏 提交于 2020-01-06 12:19:06
问题 We have a service based application in .net core which would run as a daemon in Linux environment. Everything is working as expected but i am having problem in handling dependency injection. Below is the code for reference Program.cs class Program { static async Task Main(string[] args) { Console.WriteLine("Starting PreProcessor Application "); try { ConfigParameters.LoadSettings(args); } catch (Exception ex) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine($"Error in setting

Websocket singleton who uses Scoped Service

*爱你&永不变心* 提交于 2020-01-06 08:17:30
问题 I have implemented WebSocket middleware who has contains as a field singleton WebSocket dictionary(injected via constructor) and some other scoped parameters injected via constructor. I would like to know if it's implemented correctly. public WebSocketManagerMiddleware(RequestDelegate next, IWebSocketConnectionDictionary webSocketDictionary, IScopedServiceOne scopedOneService, IScopedServiceTwo scopedtwoService) { _next = next; _webSocketManager = webSocketDictionary; _scopedOneService=

Instantiating and Invoking TagHelpers Manually

两盒软妹~` 提交于 2020-01-06 07:59:30
问题 This is a follow up question to this question, which seems to be for an older ASP.NET Core version (I'm using 2.1). I'm trying to call a TagHelper manually from within a TagHelper. Applying the Answer in the linked question above, the TagHelper.Process looks like so: public override async void Process(TagHelperContext context, TagHelperOutput output) { var anchorTagHelper = new AnchorTagHelper { Action = "Home", }; var anchorOutput = new TagHelperOutput("a", new TagHelperAttributeList(),

Dagger2 Field Injection not working

无人久伴 提交于 2020-01-06 07:59:14
问题 I am familiar with Spring dependency injection, but Dagger2 is new to me. I am trying to get a simple java application working but field injection does not work. I have a class Main , that depends on a class MainBusiness which in turn depends on MainDao . MainBusiness gets injected into Main fine, but MainDao does not get injected into MainBusiness and throws a NullPointerException . Here is the MainDao that implements an interface IMainDao public class MainDao implements IMainDao { @Inject

Dagger2 Field Injection not working

99封情书 提交于 2020-01-06 07:59:10
问题 I am familiar with Spring dependency injection, but Dagger2 is new to me. I am trying to get a simple java application working but field injection does not work. I have a class Main , that depends on a class MainBusiness which in turn depends on MainDao . MainBusiness gets injected into Main fine, but MainDao does not get injected into MainBusiness and throws a NullPointerException . Here is the MainDao that implements an interface IMainDao public class MainDao implements IMainDao { @Inject

How do I pass dependent classes to extension methods?

≡放荡痞女 提交于 2020-01-06 07:22:09
问题 I have a requirement to connect to the server and collect data for processing. Below is my core class, which is responsible for looping through all the servers and try connecting them for processing. public class CoreDataProcessingEngine : ICoreDataProcessingEngine { private readonly COMLib.ServerGateway _aServerGw; private COMLib.ServerErrorInfo _aServerErrorInfo; Public CoreDataProcessingEngine() { _aServerGw = new COMLib.ServerGateway(); _aServerErrorInfo = new COMLib.ServerErrorInfo(); }

Is the Configuration object in Asp.Net Core 2.0, injectable in a class library project

狂风中的少年 提交于 2020-01-06 06:10:21
问题 I have had no problem setting up classes in Class Libraries, setting them up in services in the Startup.cs to be injectable and having them work as expected. In a test app I am working in. I have a data class library project plus my MVC app project (Core 2.0.1 and EF 2.0.1 and MVC6) In Startup.cs // *If* you need access to generic IConfiguration this is **required** services.AddSingleton<IConfiguration>(Configuration); services.AddOptions(); // Add our class objects so they can be injected

Is the Configuration object in Asp.Net Core 2.0, injectable in a class library project

▼魔方 西西 提交于 2020-01-06 06:08:48
问题 I have had no problem setting up classes in Class Libraries, setting them up in services in the Startup.cs to be injectable and having them work as expected. In a test app I am working in. I have a data class library project plus my MVC app project (Core 2.0.1 and EF 2.0.1 and MVC6) In Startup.cs // *If* you need access to generic IConfiguration this is **required** services.AddSingleton<IConfiguration>(Configuration); services.AddOptions(); // Add our class objects so they can be injected

Configuring spring validation and hibernate validation

瘦欲@ 提交于 2020-01-06 05:59:31
问题 Problem already solved here but didn't work for me (not same spring boot version i guess) this Trying to code a custom constraint validator, to check whether account email exists before persisting. @Email @NotNull @NotBlank @Documented @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = UniqueCompteEmailValidator.class) @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) public @interface UniqueCompteEmail { String message() default "{com.mssmfactory

Property injection without using attribute [Inject] with Ninject

我们两清 提交于 2020-01-06 05:50:45
问题 I have a controller and a customized ActionInvoker. I can set the customized ActionInvoker as following, public HomeController() { this.ActionInvoker = new MyActionInvoker(..); } But don't want to do this in every controller (and I don't want to use a base controller either). I want to use Ninject to inject the ActionInvoker. Since ActionInvoker is part of the base controller I can't add [inject] to it. I searched a lot and tried something like Bind<HomeController>().ToSelf()