dependency-injection
Dependency injecting UserStore in OWIN startup using Ninject OWIN middleware
For info: It is possible to register the kernel as a singleton so that the same kernel can be used by the ninject middleware and also registered within the owin context. public static StandardKernel CreateKernel() { if (_kernel == null) { _kernel = new StandardKernel(); _kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); _kernel.Load(Assembly.GetExecutingAssembly(), Assembly.Load(“Super.CompositionRoot”)); } return _kernel; } The callback function …
Are primitive constructor parameters a bad idea when using an IoC Container? [closed]
Well I ended up redesigning this after reading the book Dependency Injection in .Net (I highly recommend this book to any object-oriented developer, not just .Net developers and not just those interested in using an IoC container!). I’ve now got the following in a Domain assembly: public interface IImageFileService { void RenameFiles(); void CopyFiles(); } …
Constructor injection with Quartz.NET and Simple Injector
According to this blog post, you would need to implement a custom IJobFactory, like this: public class SimpleInjectorJobFactory : IJobFactory { private readonly Container container; private readonly Dictionary<Type, InstanceProducer> jobProducers; public SimpleInjectorJobFactory( Container container, params Assembly[] assemblies) { this.container = container; // By creating producers, jobs can be decorated. var transient = Lifestyle.Transient; this.jobProducers = …
Using Dependency Injection with .NET Core Class Library (.NET Standard)
You don’t have to do anything in your class library. Only the main application has a composition root (earliest point in an application lifecycle you can set up your object graph). This happens in Startup.cs in your ASP.NET Core application. There you also register your dependencies: services.AddScoped<IUserManager,UserManager>(); That’s it. Class libraries don’t have a composition …
When would you use the Common Service Locator?
Imagine you are writing library code to be used by 3rd party developers. Your code needs to be able to create service objects that these developers provide. However you don’t know which IoC container each of your callers will be using. The Common Service Locator lets you cope with the above without forcing a given …
Why is $provide only available in the ‘angular.mock.module’ function, and $q only available in the ‘angular.mock.inject’ function?
You can’t use $provide within the inject function because the former registers providers for the latter to use. Take a look: describe(‘…’, function() { beforeEach(function() { module(function($provide) { $provide.constant(‘someValue’, ‘foobar’); }); inject(function(someValue) { var value = someValue; // will be ‘foobar’; }); }); }); You can though write your test this way: describe(‘…’, function() { …
using Spring JdbcTemplate – injecting datasource vs jdbcTemplate
You can do what you want. The javadoc of JdbcTemplate even clearly says it: Can be used within a service implementation via direct instantiation with a DataSource reference, or get prepared in an application context and given to services as bean reference.
When to use TryAddSingleton or AddSingleton?
As you already noticed, the difference between TryAddSingleton and AddSingleton is that AddSingleton always appends the registration to the collection, while TryAddSingleton only does this when there exists no registration for the given service type. When multiple registrations exist for the same service type, but a single instance is requested, .NET Core will always return …