dependency-injection

How to Inject Dependencies to Dynamically Loaded Assemblies

ⅰ亾dé卋堺 提交于 2020-04-10 18:08:55
问题 I have a manager class that loads various plug-in modules contained in separate assemblies through reflection. This modules are communication to the outside world (WebAPI, various other web protocols). public class Manager { public ILogger Logger; // Modules need to access this. private void LoadAssemblies() { // Load assemblies through reflection. } } These plug-in modules must communicate with an object contained within the manager class. How can I implement this? I thought about using

How to Inject Dependencies to Dynamically Loaded Assemblies

 ̄綄美尐妖づ 提交于 2020-04-10 18:07:21
问题 I have a manager class that loads various plug-in modules contained in separate assemblies through reflection. This modules are communication to the outside world (WebAPI, various other web protocols). public class Manager { public ILogger Logger; // Modules need to access this. private void LoadAssemblies() { // Load assemblies through reflection. } } These plug-in modules must communicate with an object contained within the manager class. How can I implement this? I thought about using

.NET Core 2.0 Autofac Register Class InstancePerRequest doesn't work

情到浓时终转凉″ 提交于 2020-04-10 08:17:52
问题 Here is my interface public interface IMatchServices { string MatchList(); } and class here public class MatchServices : IMatchServices { public string MatchList() { return "test"; } } Controller public class SearchController : Controller { private readonly IMatchServices matchservices; public SearchController(IMatchServices matchservices) { this.matchservices = matchservices; } [Route("matchlist")] public string MatchList() { return matchservices.MatchList(); } } and ConfigureService public

Calling 'BuildServiceProvider' from application code results in copy of Singleton warning. How do I avoid this?

旧城冷巷雨未停 提交于 2020-04-09 21:32:51
问题 I just pasted the 4 lines at the end from another project and it works but I get a warning.. I clearly do not understand DI well enough ... What does it want me to change ? public void ConfigureServices(IServiceCollection services) { if (HostingEnvironment.EnvironmentName == "Local") { services.AddHealthChecksUI() .AddHealthChecks() .AddCheck<TestWebApiControllerHealthCheck>("HomePageHealthCheck") .AddCheck<DatabaseHealthCheck>("DatabaseHealthCheck"); } services.Configure<PwdrsSettings>

Calling 'BuildServiceProvider' from application code results in copy of Singleton warning. How do I avoid this?

女生的网名这么多〃 提交于 2020-04-09 21:32:43
问题 I just pasted the 4 lines at the end from another project and it works but I get a warning.. I clearly do not understand DI well enough ... What does it want me to change ? public void ConfigureServices(IServiceCollection services) { if (HostingEnvironment.EnvironmentName == "Local") { services.AddHealthChecksUI() .AddHealthChecks() .AddCheck<TestWebApiControllerHealthCheck>("HomePageHealthCheck") .AddCheck<DatabaseHealthCheck>("DatabaseHealthCheck"); } services.Configure<PwdrsSettings>

(Laravel) Dynamic dependency injection for interface, based on user input

喜你入骨 提交于 2020-04-07 11:36:51
问题 I am currently facing a very interesting dilemma with my architecture and implementation. I have an interface called ServiceInterface which have a method called execute() Then I have two different implementations for this interface: Service1 and Service2 , which implements the execute method properly. I have a controller called MainController and this controller has a "type-hint" for the ServiceInterface ( dependency injection ), it means that both, Service1 and Service2 , can be called as

(Laravel) Dynamic dependency injection for interface, based on user input

北战南征 提交于 2020-04-07 11:36:46
问题 I am currently facing a very interesting dilemma with my architecture and implementation. I have an interface called ServiceInterface which have a method called execute() Then I have two different implementations for this interface: Service1 and Service2 , which implements the execute method properly. I have a controller called MainController and this controller has a "type-hint" for the ServiceInterface ( dependency injection ), it means that both, Service1 and Service2 , can be called as

Does ASP.NET Core's DI container assures order of services?

£可爱£侵袭症+ 提交于 2020-04-06 19:04:12
问题 When I register multiple services to the DI container with the same interface and then request an IEnumerable<IService> , do the container guarantee that the order of registration will be the order of the collection? because this seems to be the behavior but I couldn't find anything about it in the documentation. Example - let's say we have this interface: public interface IStep { void Execute(); } And some implementations: public class FirstStep : IStep { ... } public class SecondStep :

Does ASP.NET Core's DI container assures order of services?

旧巷老猫 提交于 2020-04-06 19:03:09
问题 When I register multiple services to the DI container with the same interface and then request an IEnumerable<IService> , do the container guarantee that the order of registration will be the order of the collection? because this seems to be the behavior but I couldn't find anything about it in the documentation. Example - let's say we have this interface: public interface IStep { void Execute(); } And some implementations: public class FirstStep : IStep { ... } public class SecondStep :

How to write unit test for azure function (Httptrigger) with ILogger

混江龙づ霸主 提交于 2020-04-06 03:37:19
问题 Want to write unit test for HttpTrigger GET. Have method signature as follow: public static async Task<HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestMessage request, ILogger log) here, ILogger is type of Microsoft.Extensions.Logging. How to write unit test case with this injection, Tried to create stub of ILogger using below stuff but this needs LoggerFactory . public class LoggerWriter : Microsoft.Extensions.Logging.Logger<ILogger> {