unity-container

Dependency injection vs assembly dependencies

守給你的承諾、 提交于 2019-12-04 07:27:21
Say, that I have the following project structure: Application <-> BusinessLogic <-> DataAccessLayer I've prepared all types to use poor-man's-dependency-injection and now I want to introduce the real one using Unity. But I'm struggling on where to put the dependency container and its configuration (i suppose I'll configure it from code). DataAccessLayer needs to register Context (EF) BusinessLogic needs to register data repositories (which use context) Application needs to register services (which use repositories) For now, the only assembly, which uses the container to actually instantiate

interface and cannot be constructed on Unity config

為{幸葍}努か 提交于 2019-12-04 07:06:23
问题 I have trouble to use Unity on this project. The error is The current type, Business.Interfaces.IPersonnelBusiness, is an interface and cannot be constructed. Are you missing a type mapping? I've updated the Unity to thge latest version because of stackoverflow issueand I saw that RegisterComponents has changed to lazy loaded one here is the Global asax: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

Unity: Register two interfaces as one singleton with interception

怎甘沉沦 提交于 2019-12-04 06:25:41
I have a class that implements two interfaces, and I want to apply interception to the class's methods. I'm following the advice in Unity Register two interfaces as one singleton , but I'm surprised by the results. In a nutshell, it seems that my CallHandler is called twice. The shortest example I have is this: public interface I1 { void Method1(); } public interface I2 { void Method2(); } public class C : I1, I2 { [Log] public void Method1() {} public void Method2() {} } public class LogAttribute : HandlerAttribute { public override ICallHandler CreateHandler(IUnityContainer container) {

Random “Missing type map configuration or unsupported mapping.” Error in Automapper

混江龙づ霸主 提交于 2019-12-04 06:11:32
问题 Please see this post for the solution. Ok, I finally figured it out. The: AppDomain.CurrentDomain.GetAssemblies() piece of my code sometimes does not get my mapping assembly so while it is missing I get an error. Replacing this code by forcing the app to find all assemblies solved my problem. My Entity: /// <summary> /// Get/Set the name of the Country /// </summary> public string CountryName { get; set; } /// <summary> /// Get/Set the international code of the Country /// </summary> public

ASP.NET MVC 3 Dependency Injection - Controllers, Views & Action Filters

送分小仙女□ 提交于 2019-12-04 05:23:10
I'm trying to get dependency injection working in an ASP.NET MVC 3 application using Microsoft Unity. First i have implemented my own IDependencyResolver and activated it in my Global.asax file like so: DependencyResolver.SetResolver(new UnityDependencyResolver(container)); I found that i don't need to do anything else to get controller injection (via both the constructor and [Dependency] attribute) to work. With the default view engine i also found i could get the [Dependency] attribute to work in the standard views but not the Layout views. Is it possible to get this to work for the Layout

Unity constructor parameters

血红的双手。 提交于 2019-12-04 05:15:50
class Entity:IEntityName { #region IEntityName Members public string FirstName { get; set; } public string LastName { get; set; } #endregion } public class Person:IPerson { public IEntityName EntityName; public Person() { } public Person(IEntityName EntityName) { this.EntityName = EntityName; } public string ReverseName() { return string.Format("Your reverse name is {0} {1}",EntityName.LastName, EntityName.FirstName); } public override string ToString() { return string.Format("Name is {0} {1}", EntityName.FirstName, EntityName.LastName); } } // Main Method private static string

Castle Windsor Typed Factory Facility equivalents

一世执手 提交于 2019-12-04 05:12:42
do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor? e.g. if I am using an abstract factory pattern in a WPF application: public class MyViewModel { private IAnotherViewModelFactory factory; public void ShowAnotherViewModel() { viewController.ShowView(factory.GetAnotherViewModel()); } } I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container to take care of this for me. AutoFac has a feature called Delegate Factories , but as far as I can

Custom ActionInvoker vs custom FilterProvider for ActionFilter dependency injection in MVC 3

我们两清 提交于 2019-12-04 05:11:24
Can anyone shed some light on the advantages and disadvantages of using a custom ActionInvoker like so to perform dependency injection on custom ActionFilters as opposed to using a custom FilterProvider as demonstrated here ? In both cases you are going to still want to avoid constructor injection on your ActionFilters, and to me it seems that all the custom FilterProvider does in this case is adds additional overhead of having to register your ActionFilters and the provider in your container. The big advantage of filter providers is that it allows constructor injection if done right. The

Can't inject on System.Web.Http.Filters.ActionFilterAttribute using Unity bootstrapper for ASP.NET Web API nuget package

允我心安 提交于 2019-12-04 04:39:39
I can't get dependency injection working with a custom ActionFilterAttribute class using the Unity bootstrapper for ASP.NET Web API nuget package. I've registered the type in UnityConfig and I'm using it elsewhere (using constructor injection there though) and it works fine. public static void RegisterTypes(IUnityContainer container) { container.RegisterType<ISettingService, SettingService>(); ... } The code is being called successfully, however the instantiated object (settingService) is null. public class APIKeyValidationAttribute : ActionFilterAttribute { [Dependency] public ISettingService

How can I register one singleton to different interfaces in unity, XML config?

社会主义新天地 提交于 2019-12-04 03:48:32
How to do it in code is explained here: Unity Register two interfaces as one singleton _container.RegisterType<EventService>(new ContainerControlledLifetimeManager()); _container.RegisterType<IEventService, EventService>(); _container.RegisterType<IEventServiceInformation, EventService>(); bool singleton = ReferenceEquals(_container.Resolve<IEventService>(), _container.Resolve<IEventServiceInformation>()); How to do it in the XML config? Personally I like to spell out namespaces and assemblies in aliases. So xml: <unity xmlns="http://schemas.microsoft.com/practices/2010/unity"> <alias alias=