unity-container

Enterprise Library Unity vs Other IoC Containers [closed]

拥有回忆 提交于 2019-11-26 07:51:02
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . What\'s pros and cons of using Enterprise Library Unity vs other IoC containers (Windsor, Spring.Net, Autofac ..)? 回答1: I am preparing a presentation for a usergroup. As such I just went through a bunch of them. Namely: AutoFac, MEF, Ninject, Spring.Net, StructureMap, Unity,

Is there a good/proper way of solving the dependency injection loop problem in the ASP.NET MVC ContactsManager tutorial?

不羁岁月 提交于 2019-11-26 07:44:08
问题 If you don\'t know what I\'m talking about either go through the tutorial and try to add dependency Injection yourself or try your luck with my explanation of the problem. Note: This problem isn\'t within the scope of the original tutorial on ASP.NET. The tutorial only suggests that the patterns used are dependency injection friendly. The problem is basically that there is a dependency loop between the Controller, the ModelStateWrapper and the ContactManagerService. The ContactController

Dependency Injection in attributes

喜夏-厌秋 提交于 2019-11-26 05:54:36
问题 I am trying to inject a dependency into a custom AuthorizeAttribute as follows: public class UserCanAccessArea : AuthorizeAttribute { readonly IPermissionService permissionService; public UserCanAccessArea() : this(DependencyResolver.Current.GetService<IPermissionService>()) { } public UserCanAccessArea(IPermissionService permissionService) { this.permissionService = permissionService; } protected override bool AuthorizeCore(HttpContextBase httpContext) { string AreaID = httpContext.Request

When to use PerThreadLifetimeManager?

你说的曾经没有我的故事 提交于 2019-11-26 05:38:20
问题 I am following the example linked to below for setting up unity to work with my service layer. My project is setup very similar to the one in this article and I understand everything except why exactly is PerThreadLifetimeManager used when registering the service dependency. Keep in mind I am also using a generic repository and unitofwork that is being used in my service layer as well. Most unity examples use the default(transient) lifetime manager, and since my setup is similar to the one

Dependency Injection Unity - Conditional Resolving

瘦欲@ 提交于 2019-11-26 04:25:50
Conditional resolving is the last thing I don't understand at the moment. Lets say we have an interface IAuthenticate : public interface IAuthenticate{ bool Login(string user, string pass); } Now I have two types of authentication. Twitter auth public class TwitterAuth : IAuthenticate { bool Login(string user, string pass) { //connect to twitter api } } Facebook Auth public class FacebookAuth: IAuthenticate { bool Login(string user, string pass) { //connect to fb api } } Registering types in unity config: unityContainer.RegisterType<IAuthenticate, TwitterAuth>(); unityContainer.RegisterType

How do you reconcile IDisposable and IoC?

南笙酒味 提交于 2019-11-26 04:20:52
问题 I\'m finally wrapping my head around IoC and DI in C#, and am struggling with some of the edges. I\'m using the Unity container, but I think this question applies more broadly. Using an IoC container to dispense instances that implement IDisposable freaks me out! How are you supposed to know if you should Dispose()? The instance might have been created just for you (and therefor you should Dispose() it), or it could be an instance whose lifetime is managed elsewhere (and therefor you\'d

Unity Inject dependencies into MVC filter class with parameters

心不动则不痛 提交于 2019-11-26 02:38:20
问题 I\'m using Unity.MVC4 dependency injection for accessing my services. Everything works as it should when injecting into my Controller constructor, but what I would like to do now is to use property injection in my filter class so I can access my database from the inside. Before I started this question I Googled around and tried different examples but I couldn\'t find a solution that worked for me.. Bootstrapper.cs public static class Bootstrapper { public static IUnityContainer Initialise() {

Is there a pattern for initializing objects created via a DI container

走远了吗. 提交于 2019-11-26 01:19:40
问题 I am trying to get Unity to manage the creation of my objects and I want to have some initialization parameters that are not known until run-time: At the moment the only way I could think of the way to do it is to have an Init method on the interface. interface IMyIntf { void Initialize(string runTimeParam); string RunTimeParam { get; } } Then to use it (in Unity) I would do this: var IMyIntf = unityContainer.Resolve<IMyIntf>(); IMyIntf.Initialize(\"somevalue\"); In this scenario runTimeParam

Dependency Injection Unity - Conditional Resolving

笑着哭i 提交于 2019-11-26 01:16:36
问题 Conditional resolving is the last thing I don\'t understand at the moment. Lets say we have an interface IAuthenticate : public interface IAuthenticate{ bool Login(string user, string pass); } Now I have two types of authentication. Twitter auth public class TwitterAuth : IAuthenticate { bool Login(string user, string pass) { //connect to twitter api } } Facebook Auth public class FacebookAuth: IAuthenticate { bool Login(string user, string pass) { //connect to fb api } } Registering types in

Is it better to create a singleton to access unity container or pass it through the application? [closed]

风流意气都作罢 提交于 2019-11-26 01:15:19
问题 I am dipping my toe into using a IoC framework and I have choosen to use Unity. One of the things that I still don\'t fully understand is how to resolve objects deeper into the application. I suspect I just haven\'t had the light bulb on moment that will make it clear. So I am trying do something like the following in psuedo\'ish code void Workflow(IUnityContatiner contatiner, XPathNavigator someXml) { testSuiteParser = container.Resolve<ITestSuiteParser> TestSuite testSuite = testSuiteParser