unity-container

Unity / EntLib: Injecting a dependency into a CustomTraceListener

故事扮演 提交于 2019-12-01 00:47:05
Sorry, this is quite a special topic so this may not be of interest to many. :-( However, I need to do the following thing: I have an application that provides logging to some kind of console window (it's a WPF window, because of application requirements and because the application needs to look flashy even here - our special customer asked for that and talks about it every time we meet) To provide thread - agnostic logging I created an interface / implementation pair "IGUIController" / "GUIController" So far, so good. It's all fine. However: I need my own custom trace listener (I call it

Typical IoC container usage - passing data down the line

▼魔方 西西 提交于 2019-11-30 22:42:23
I've recently started using an IoC container for the first time, but I'm not educated on the best practices for using it. More specificaly I'm using Unity in a C# .NET project, and I started using it because it came with Prism . I use the container to resolve the "top level" objects, and they get the correct objects injected based on the container. However, I can't see the best practice clearly when I have an object with children and children's children, and I need some data from the IoC container all the way down, but not in between. How you'd typically organize the use of IoC container?

Getting Unity to Resolve views in XAML

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 22:05:49
I'm starting out with MVVM, and I'm starting to understand things. I'm currently experimenting with the Cinch framework, though I'm not committed to it as of yet. I was injecting the ViewModels into the Views using by having a reference to the ViewModel in the codebehind of the view, with the property having a [Dependency] on it, and in the setter it sets the DataContext to the right view, using Unity. Neat trick, I thought. I'm trying to get my app to work as a single Window, with injected views (As opposed to multiple windows and dealing with opening\closing them) I changed my views from

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

江枫思渺然 提交于 2019-11-30 21:10:30
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 an object element because it is not public or does not define a public parameterless constructor or a

Multiple consumers for the same message through Unity not working in MassTransit

半城伤御伤魂 提交于 2019-11-30 20:46:10
I'm having a lot of problems lately because of what seems to be a bug in the MassTransit.UnityIntegration package, primarily due to the fact that registration names are not being considered. For instance, if I register my classes like this: var container = new UnityContainer() .RegisterType<Consumes<Command1>.All, Handler1>("Handler1") .RegisterType<Consumes<Command1>.All, Handler3>("Handler3"); A few lines later, I use the LoadFrom extension method to get the registered consumers in the container like this: IServiceBus massTransitBus = ServiceBusFactory.New(_sbc => { _sbc.UseBinarySerializer(

How to configure a logging interceptor for all registered type in Unity?

别来无恙 提交于 2019-11-30 20:33:18
I am going to trace every actions happened in the services which are managed by the Unity Container as logs in file system. I suppose I could define an interface named IService and all the other interfaces or implementation should inherit from him. On the other hand, I would like to develop a custom interception behavior or call handler to save the logs into files. Unfortunately, I found that it doesn't work for me by using this codes IUnityContainer unity = new UnityContainer(); //Interception unity.AddNewExtension<Interception>(); Interception interception = unity.Configure<Interception>();

Unity: Register and resolve class with generic type

岁酱吖の 提交于 2019-11-30 20:30:39
I'm using Unity and try to follow to SOLID-principles as far as possible. Therefore all implementations only have dependencies to interfaces. I have a collectionwrapper which looks like this: public interface ICollectionWrapper<TModel> { int TotalCount { get; set; } IEnumerable<TModel> Items { get; set; } } Now I want to create the instance of ICollectionFactory<T> with a factory. This is what I got so far: public interface ICollectionWrapperFactory { ICollectionWrapper<T> CreateCollection<T>(); ICollectionWrapper<T> CreateCollection<T>(IEnumerable<T> items); ICollectionWrapper<T>

Unity / EntLib: Injecting a dependency into a CustomTraceListener

徘徊边缘 提交于 2019-11-30 19:54:26
问题 Sorry, this is quite a special topic so this may not be of interest to many. :-( However, I need to do the following thing: I have an application that provides logging to some kind of console window (it's a WPF window, because of application requirements and because the application needs to look flashy even here - our special customer asked for that and talks about it every time we meet) To provide thread - agnostic logging I created an interface / implementation pair "IGUIController" /

Using Unity IoC to register and resolve SignalR hubs

廉价感情. 提交于 2019-11-30 19:22:17
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 PerRequestLifetimeManager()); container.RegisterType<SignalRConnectionRepository>(new PerRequestLifetimeManager()); //Context

Unity constructor injection with other parameter

孤人 提交于 2019-11-30 18:12:54
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>() As you can see, I have a string parameter called user as part of the constructor to BatchService