unity-container

Dependency Injection using Template 10

烂漫一生 提交于 2019-12-19 11:37:14
问题 I am trying to migrate some code from an old Windows 8.1 app that I had developed using Prism/Unity to a new UWP app using Template 10 and Unity. I have seen in the documentation for Template 10 here that you can override the ResolveForPage method. In my old Windows 8.1 app, there is a Resolve method in Prism that I would override like this: protected override object Resolve(Type type) { return Container.Resolve(type); } The signature for the Template 10 method is public override INavigable

Using Unity to inject objects into IValueConverter instance

删除回忆录丶 提交于 2019-12-19 07:11:23
问题 I have an instance of IValueConverter in a Silverlight 5 project, which converts custom data into different colors. I need to read the actual color values from a database (as these can be edited by the user). Since Silverlight uses asynchronous calls to load the data through Entity Framework from the database, I created a simple repository, which holds the values from the db. The interface: public interface IConfigurationsRepository { string this[string key] { get; } } The implementation:

Aspect Oriented Logging with Unity\T4\anything else

时光怂恿深爱的人放手 提交于 2019-12-19 07:00:11
问题 In my application we have a trace logger. We have log statements added at the beginning and end of most of the important methods tracing the method name and the parameter values. Now these trace statements are bloating the code and it is a bit of a pain to read through them. I am considering how can I separate this aspect of the code from my business logic. Today I was reading about Unity's interception framework. I had a passing thought if it is possible to intercept my method calls with a

How to declare the Unity InjectionFactory in XML configuration

 ̄綄美尐妖づ 提交于 2019-12-19 06:17:29
问题 I'm in the process of moving our Unity configuration to the web.config file. I'm stuck on how to migrate the following code config to the xml format: var container = new UnityContainer(); container.RegisterType<IPrincipal>(new InjectionFactory(x=> HttpContext.Current.User)); return container; Here are the XML declartion: <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <alias alias="IRepository" type="Model.IRepository, Model" /> <alias alias="Repository" type="Data

Can a unity container pass a reference of itself as a constructor parameter?

那年仲夏 提交于 2019-12-19 05:07:14
问题 Is there a way for a unity container to pass itself to an object? i.e.: public class Something { public Something(IUnityContainer container) { ... } } 回答1: The short answer is yes. This should be passed automatically when you use the Resolve methods. For example: IUnityContainer container = new UnityContainer(); var something = container.Resolve<Something>(); Additionally, this is the same technique that Prism (on CodePlex) uses if you want to look into that. Update Added Test: [TestClass]

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

邮差的信 提交于 2019-12-19 03:11:28
问题 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(); /

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

风流意气都作罢 提交于 2019-12-19 03:09:23
问题 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

Unity application block 2.0 - The given assembly name or codebase was invalid

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 19:05:19
问题 Interfaces (In the assembly named "Interfaces". In project :- Interfaces) namespace Interfaces { public interface IDoSomeWork1 { string DoSomeWork1(); } } namespace Interfaces { public interface IDoSomeWork2 { string DoSomeWork2(); } } Dependencies (In the assembly named "Entities". In project :- Entities) namespace Entities { public class ClassB : IDoSomeWork1 { public string DoSomeWork1() { return this.ToString(); } } } namespace Entities { public class ClassC : IDoSomeWork2 { public string

Using Unity With Minimal Configuration

我与影子孤独终老i 提交于 2019-12-18 17:03:40
问题 At work, we use Unity a lot. It's great at it's job, but the more you use it, the more your configuration file grows, the more runtime issues increase and the more you have to recreate your unity configuration for each test project. So we end up with a huge unity configuration section that has to be duplicated accross several projects and when it comes time to deploy, you end up having to track down dlls that you forgot to add references to, but you only discover these at runtime. Not fun. I

An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll

烈酒焚心 提交于 2019-12-18 16:17:13
问题 In my Asp.net MVC project I have a bootsrapper that initialize a unity-container. I don't know why, but I get An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll I have doubled checked and registration is done only in my initializer. All dependencies are injected in the ctors only. What could have caused this? protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig