dependency-injection

How to do open generic decorator chaining with unity + UnityAutoRegistration

杀马特。学长 韩版系。学妹 提交于 2019-12-17 19:37:12
问题 Went off on an interesting tangent today after reading this article on command handler decoration. I wanted to see if I could implement the pattern using Unity instead of SimpleInjector, and so far it is proving extremely difficult. The first thing I had to do was install UnityAutoRegistration to resolve the open generic ICommandHandler<TCommand> interface. Current solution for that aspect is as follows: Container = new UnityContainer().LoadConfiguration(); Container.ConfigureAutoRegistration

Dependency Injection with .NETCore for DAL and connection string

无人久伴 提交于 2019-12-17 19:17:25
问题 I am new to the DI patterns with .NETCore, and I am having trouble getting my connection strings to my DAL. I followed the advice given in this thread via the accepted answer, and subsequent comments. This is my base class public class BaseRepository : IRepository<IDataModel> { private readonly IConfiguration config; public BaseRepository(IConfiguration config) { this.config = config; } public string GetSQLConnectionString() { return config["Data:DefaultConnetion:ConnectionString"]; } This is

.net Core Quartz Dependency Injection

孤街浪徒 提交于 2019-12-17 19:15:15
问题 How can I configure Quartz in .net core to use dependency injection? I using standard .net core Dependency mechanism. In constructor of class that implements IJob , I need inject some dependencies. 回答1: You can use the Quartz.Spi.IJobFactory interface and implement it. The Quartz documentations states: When a trigger fires, the Job it is associated to is instantiated via the JobFactory configured on the Scheduler. The default JobFactory simply activates a new instance of the job class. You

vNext Dependency Injection Generic Interface

Deadly 提交于 2019-12-17 18:58:33
问题 I have created an ASP.Net vNext Web API. I have successfully used the dependency inection with a simple interface such as this: services.AddScoped<ILinearRegressionCalculator, LinearRegressionCalculator>(); However, I can't figure out how to do dependency inection with a Generic Interface. How do I setup dependency injection for this interface: public interface IMongoConnectionHandler<T> where T : IMongoEntity 回答1: Following is an example: services.TryAdd(ServiceDescriptor.Singleton(typeof

Unity: Implicit ResolvedParameter for unnamed registrations

有些话、适合烂在心里 提交于 2019-12-17 18:30:13
问题 The UserService constructor has two parameters, a IUnitOfWork and a IUserRepository : public UserService(IUnitOfWork unitofWork, IUserRepository userRepository) { ... } I am using named registrations to differentiate between multiple instances of IUnitOfWork , so when registering the UserService with the Unity container, I need to explicitly specify the parameters using an InjectionConstructor : container.RegisterType<IUserService, UserService>( new InjectionConstructor( new ResolvedParameter

Using Unity to inject dependencies into a custom ActionFilter

别等时光非礼了梦想. 提交于 2019-12-17 18:29:56
问题 At the moment, I have a custom ControllerFactory into which I inject my Unity container: in global.asax Application_Start(): var container = InitContainer(); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); var factory = new UnityControllerFactory(container); ControllerBuilder.Current.SetControllerFactory(factory); In the controller factory I set my controllers to use a custom ActionInvoker like so: protected override IController GetControllerInstance(System.Web.Routing

Autofac in web applications, where should I store the container for easy access?

一笑奈何 提交于 2019-12-17 18:24:56
问题 I'm still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places in a web application. I know I can use the Autofac controller factory to automatically resolve constructor injected dependencies for controllers, but how about the other stuff you might need to resolve that is not injected yet. Is there an obvious pattern I am not aware of for this? Thank you! 回答1: First of all try not to

How can I combine MVVM and Dependency Injection in a WPF app?

百般思念 提交于 2019-12-17 18:20:18
问题 Can you please give an example of how you would use (your favorite) DI framework to wire MVVM View Models for a WPF app? Will you create a strongly-connected hierarchy of View Models (like where every nested control's ViewModel is a property on a parent's ViewModel and you bind it to nested control's DataContext in XAML) or you would use some kind of even-more-abstract ""View Model" Manager", which maintains some weakly-connected hierarchy... like in CAB, maybe? 回答1: If a view model can only

What are the specific benefits of using DI on Android?

女生的网名这么多〃 提交于 2019-12-17 18:17:09
问题 What are the specific benefits or advantages of using a dependency injection framework for Android, like Dagger, Transfuse or RoboGuice? For example, what kind of apps would benefit the most from using DI? is there more of a performance advantage, or is it more on the ease of extending an app, or even more about making it testable? One of the reasons for asking this is to gauge if an app I'm developing would actually benefit from it or not much. Since I intend the app to be serious at some

Dependency injection, inject with parameters

独自空忆成欢 提交于 2019-12-17 18:13:01
问题 I'm using vNext implementation of DI. How to pass parameters to constructor? For example, i have class: public class RedisCacheProvider : ICacheProvider { private readonly string _connectionString; public RedisCacheProvider(string connectionString) { _connectionString = connectionString; } //interface methods implementation... } And service register: services.AddSingleton<ICacheProvider, RedisCacheProvider>(); How to pass parameter to constructor of RedisCacheProvider class? For example for