unity-container

How to I connect a ViewModel to a View when the view model has parameters in the constructor?

吃可爱长大的小学妹 提交于 2019-11-30 05:24:40
问题 I'm using Prism and Unity to rewrite a WPF application using the MVVM pattern. Most of the Views are connected to the VM via the DataContext property, like so: <UserControl.DataContext> <VM:RibbonViewModel/> </UserControl.DataContext> The problem is that this method will not work when there is a parameter in the ViewModel's constructor. public RibbonViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; } I get the error: Type 'RibbonViewModel' is not usable as

SynchronizationContext.Current is null on resolving with Unity in WPF

爷,独闯天下 提交于 2019-11-30 05:21:38
问题 I have a WPF Code which looks something like this. public class AlphaProductesVM : BaseModel { private ObservableCollection<Alphabetical_list_of_product> _NwCustomers; private int i = 0; public AlphaProductesVM () { _NwCustomers = new ObservableCollection<Alphabetical_list_of_product>(); var repository = new NorthwindRepository(); repository .GetAllProducts() .ObserveOn(SynchronizationContext.Current) .Subscribe(AddElement); } public void AddElements(IEnumerable<Alphabetical_list_of_product>

Activation error occured while trying to get instance of type ICacheManager, key “Cache Manager”

限于喜欢 提交于 2019-11-30 03:47:38
问题 I seem to have hit a wall here and would appreciate some help from anyone who is able to on this one. I am not exactly sure what the error message below means. I am using the Caching Block of Enterprise Pattern Services but I keep running in to the problem below. I downloaded the latest version and tried stepping through to the issue but I can't seem to pin the exact problem and I need help please. Thanks in advance Test method WorldBank.Service.Business.UnitTest.TopicsManagerTest.Call

Using Unity IoC to register and resolve SignalR hubs

天涯浪子 提交于 2019-11-30 03:32:35
问题 I think I'm missing something very simple and maybe just need a new set of eyes. I have an ASP.NET MVC application. In that app, I am using Unity for my IoC to handle dependency injection. Each of my repositories need to have a database factory injected into it and each database factory needs to have a principal injected into it. So far, I've been utilizing the PerRequestLifetimeManager to register these. //Repositories container.RegisterType<ChatMessageRepository>(new

Unity constructor injection with other parameter

亡梦爱人 提交于 2019-11-30 02:37:21
问题 I have a class with a constructor that looks like the following: public BatchService(IRepository repository, ILogger logger, string user) In my DI bootstrapper class, I have the following RegisterType command: .RegisterType<BatchService>( new InjectionConstructor( new ResolvedParameter<IRepository>("SomeRepository"), new ResolvedParameter<ILogger>("DatabaseLogger"))) In my client code, I want to instantiate BatchService as follows: BatchService batchService = DIContainer.Resolve<BatchService>

Inject same DataContext instance across several types with Unity

自闭症网瘾萝莉.ら 提交于 2019-11-30 02:29:00
Suppose I have IRepository interface and its implementation SqlRepository that takes as an argument LINQ to SQL DataContext. Suppose as well that I have IService interface and its implementation Services that takes three IRepository, IRepository and IRepository. Demo code is below: public interface IRepository<T> { } public class SqlRepository<T> : IRepository<T> { public SqlRepository(DataContext dc) { ... } } public interface IService<T> { } public class Service<T,T1,T2,T3> : IService<T> { public Service(IRepository<T1> r1, IRepository<T2>, IRepository<T3>) { ... } } Is it any way while

Unity IOC Buildup vs Resolve?

痴心易碎 提交于 2019-11-30 00:37:57
问题 I was wondering when do I use buildup and when do I use resolve, when using the Unity IOC. And when do I call teardown? Thanks 回答1: Resolve is used when you want the Unity container to construct the instance (a new one just when you need it or an pre-existing singleton), inject its dependencies and hand you the reference to the object. BuildUp is used when you already have an instance of the object and want the container to just resolve and inject its dependencies. Teardown is the opposite of

Specifying a default Unity type mapping for a generic interface and class pair

泪湿孤枕 提交于 2019-11-29 22:10:04
问题 We're using constructor-based dependency injection, AutoMapper and Unity on a codebase. We have wrapped AutoMapper with a generic interface... public interface IMapper<TSource, TDestination> { TDestination Map(TSource source); } And a class that implements this interface... public class AutomaticMapper<TSource, TDestination> : IMapper<TSource, TDestination> { public TDestination Map(TSource source) { return AutoMapper.Mapper.Map<TSource, TDestination>(source); } } This works well, but it

How to inject dependencies into the global.asax.cs

跟風遠走 提交于 2019-11-29 21:19:57
How do I inject dependencies into the global.asax.cs, i.e. the MvcApplication class? Having previously used the Service Locator (anti-)pattern for dependency injection, I am trying to follow best practice advice in my latest MVC application by using an IOC container (specifically Unity.Mvc3 because it comes with an implementation of the IDependencyResolver out of the box) and constructor injection. Everything seems quite straight forward so far except for a couple of snags, one of which is in the global.asax.cs (the other is for custom attributes but there's aleady a question on SO covering

Microsoft Unity. How to specify a certain parameter in constructor?

℡╲_俬逩灬. 提交于 2019-11-29 20:55:31
I'm using Microsoft Unity. I have an interface ICustomerService and its implementation CustomerService . I can register them for the Unity container using the following code: container.RegisterType<ICustomerService, CustomerService>(new TransientLifetimeManager()); If CustomerService has a certain parameter in its constructor (e.g. ISomeService1 ), I use the following code (I need to specify SomeService1 ): container.RegisterType<ICustomerService, CustomerService>(new TransientLifetimeManager(), new InjectionConstructor(new SomeService1())); No problems here. The problem appears when