dependency-injection

Is mixing constructor-based and setter-based injections a bad thing?

牧云@^-^@ 提交于 2019-12-18 13:01:18
问题 I have a class for products import from CSV file operation which requires about 7 parameters. This is an info which is definitely needed for importer. All of this parameters have the same life time. In the end we must have an Immutable Object. I was too scared to list all of them in constructor because of its affect to readability and decided to move 3 of them to setters injection. But obviously it's not an elegant solution. Questions: 1) Is mixing constructor-based and setter-based

MEF = may experience frustration?

▼魔方 西西 提交于 2019-12-18 12:36:57
问题 UPDATE As I've tried to get MEF working throughout my application, I'm coming across more an more places where I just don't get why it's not automatically creating my library when I expect it to. I think it all comes back to what Reed was saying about needing MEF to create everything. So right now, I have an XML reader class that needs to use my CandySettings, but even though its ICandySettings property has the [Import] attribute, it doesn't get imported. First I found out that [Import] doesn

Jersey + HK2 + Grizzly: Proper way to inject EntityManager?

爱⌒轻易说出口 提交于 2019-12-18 12:34:08
问题 I've managed to set up injection (into resource classes) of my own service classes in Jersey, HK2 and a plain GrizzlyServer. (Basically followed this example.) I'm now curious what the best is to inject JPA EntityManagers into my resource classes? (I'm currently considering one request as one unit of work). One option that I'm currently exploring is to use a Factory<EntityManager> in the following way: class MyEntityManagerFactory implements Factory<EntityManager> { EntityManagerFactory emf;

Circular Reference when injecting Security Context into (Entity Listener) Class

匆匆过客 提交于 2019-12-18 12:27:25
问题 There was 2 questions here saying injecting the whole service container should solve this. But question ... see below (note difference between try 2 & 3) ... Try 1 public function __construct(SecurityContext $securityContext) { $this->securityContext = $securityContext); } Curcular Reference. Okay ... Try 2 public function __construct(ContainerInterface $container) { $this->securityContext = $container->get('security.context'); } Circular Reference ( Why? , I am injecting the container like

SignalR + Dependency Injection Questions

左心房为你撑大大i 提交于 2019-12-18 12:12:30
问题 I am using SignalR in my MVC3 application, and since I have implemented StructureMap Dependency Injection on my controllers I would like to do the same in my hub, but I can't seem to get it working. Please tell me what's wrong with my codes below: SignalRSmDependencyResolver.cs public class SignalRSmDependencyResolver : DefaultDependencyResolver { private IContainer _container; public SignalRSmDependencyResolver(IContainer container) { _container = container; } public override object

SignalR + Dependency Injection Questions

泪湿孤枕 提交于 2019-12-18 12:11:37
问题 I am using SignalR in my MVC3 application, and since I have implemented StructureMap Dependency Injection on my controllers I would like to do the same in my hub, but I can't seem to get it working. Please tell me what's wrong with my codes below: SignalRSmDependencyResolver.cs public class SignalRSmDependencyResolver : DefaultDependencyResolver { private IContainer _container; public SignalRSmDependencyResolver(IContainer container) { _container = container; } public override object

.NET Core IServiceScopeFactory.CreateScope() vs IServiceProvider.CreateScope() extension

独自空忆成欢 提交于 2019-12-18 12:08:51
问题 My understanding is that when using the built in the dependency injection, a .NET Core console app will require you to create and manage all scopes yourself whereas a ASP.NET Core app will create and manage the HttpRequest scope by default through defined middleware(s). With ASP.NET Core, you can optionally create and manage your own scopes that by calling CreateScope() for when you need services that live outside of a HttpRequest . It is clear that calling IServiceScopeFactory.CreateScope()

IoC, AOP and more

本秂侑毒 提交于 2019-12-18 11:58:01
问题 What is an IoC container? What is an IoC/DI framework? Why do we need a framework for IoC/DI? Is there any relationship between IoC/DI and AOP? What is Spring.net/ninject with respect to IoC and AOP? 回答1: JMSA, James Kovacs wrote a fantastic article which covers many of your questions I would recommend reading it Here Spring.Net, Ninject, Unity, Castle Windsor, Autofac are all IOC containers which are configurable in different ways, many of them do also support AOP. Frameworks for IOC/DI are

Why do I not need @Autowired on @Bean methods in a Spring configuration class?

假如想象 提交于 2019-12-18 11:57:47
问题 Why does this work: @Configuration public class MyConfig { @Bean public A getA() { return new A(); } @Bean <-- Shouldn't I need @Autowired here? public B getB(A a) { return new B(a); } } Thanks! 回答1: @Autowire lets you inject beans from context to "outside world" where outside world is your application. Since with @Configuration classes you are within "context world ", there is no need to explicitly autowire (lookup bean from context). Think of analogy like when accessing method from a given

ASP.NET Core IHostedService manual start/stop/pause(?)

寵の児 提交于 2019-12-18 11:47:48
问题 I would like to implement a recurring (timed) IHostedService instance in ASPNET Core that can be stopped and started on demand. My understanding is that IHostedService(s) are started by the framework on application startup. However, I would like to be able to start/stop the service 'manually', perhaps using an on/off toggle via a UI. Ideally the "off" state would dispose of currently running service, and the "on" state would then create a new instance. I've read the MS docs here: https://docs