unity-container

Migrating to Automapper 4.2.1 from Automapper 2.2.1

纵然是瞬间 提交于 2019-12-14 03:44:49
问题 I have a project where I have been using automapper 2.2.1. I upgraded to 4.2.1 and am completely broken. I tried to follow this by changing all references to Mapper.CreateMap<Source, Target>() to Mapper.Initialize(cfg => { cfg.CreateMap<Source, Target>()}) . I'm now broken bad and I cant seem to get it done.I'm getting " System.Reflection.ReflectionTypeLoadException was unhandled by user code exception with Unable to load one or more of the requested types. Retrieve the LoaderExceptions

Need complete DI sample for WCF

落爺英雄遲暮 提交于 2019-12-14 03:44:11
问题 Does anyone have a complete and working DI sample for WCF? Every sample I find just gets me more confused. Does anyone know of a complete and working standalone simple sample that works with the built in stuff? Maybe once I get a handle of the built in stuff, I can move on to different DI frameworks such as StructureMap or Unity with WCF. My MVC project is currently using Unity for all its DI. 回答1: The code download for my book Dependency Injection in .NET contains a full, working example.

Extending ActionDescriptorFilterProvider to allow dependency injection of class level filters

眉间皱痕 提交于 2019-12-14 01:06:31
问题 Following up on Authorization Filter Dependency Injection with ASP.New MVC 4 Web Api . Is there a way to use dependency injection on filters that are set globally on all controller classes: config.Filters.Add(new WebApplicationApiAuthorizeAttribute()); It looks like the GetFilters method in the ActionDescriptorFilterProvider only works on method level filters. public class UnityWebApiFilterAttributeFilterProvider : ActionDescriptorFilterProvider, System.Web.Http.Filters.IFilterProvider {

Share lifetime managers between types in Unity?

别说谁变了你拦得住时间么 提交于 2019-12-14 00:46:42
问题 The examples I've seen in the Unity documentation have you specifying the lifetime manager by putting new LifetimeManager() inline. So I have this code: container.RegisterType<ApplicationDbContext>(new PerRequestLifetimeManager()); container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new PerRequestLifetimeManager(), new InjectionConstructor(typeof (ApplicationDbContext))); container.RegisterType<UserManager<ApplicationUser>>(new PerRequestLifetimeManager()); Fine,

WCF + Unity nested web.config problem

自作多情 提交于 2019-12-13 19:22:34
问题 I'm trying to setup the following: /WebApplication web.config tokenlogin.aspx /Services web.config AccessTokenService.svc I put my WCF Service + configuration in the /WebApplication/Services folder. This still workes as expected. Now my AccessTokenService, which resides in an other assembly, expects an interface in its constructor called IAccessTokenRepository (see all code samples below). Because normally WCF only allows for parameter-less constructors, I extended WCF using a custom

Should I use Unity Config file or Code to register types and instances?

不问归期 提交于 2019-12-13 19:02:02
问题 Finally started to configure an IoC Container! I'm using Unity and have configured it to have my objects registered using the config file: e.g. <container> <register type="ILogger" mapTo="Logger"> <lifetime type="singleton"/> </register> <register type="IPdfWriter" mapTo="PdfWriter"> <lifetime type="perthread" /> <constructor /> </register> </container> I've reached a point where I doubt this is a good approach to register types. For example a class of mine is dependent on the ICacheManager

Unity to Resolve By Name

老子叫甜甜 提交于 2019-12-13 18:25:58
问题 I'm trying to get Unity to be my factory in a factory pattern, hence return different implementations of an Interface depending upon the named instance. I have the following code public static class Factory { private static readonly IUnityContainer container; static Factory() { container = new UnityContainer(); container .AddNewExtension<EnterpriseLibraryCoreExtension>() .AddNewExtension<Interception>() .RegisterType<IInterceptionBehavior, LoggingBehaviour>() //register the implemantation1

InvalidOperationException - The type does not have an accessible constructor

纵然是瞬间 提交于 2019-12-13 18:13:42
问题 I am having issues resolving WCF using Unity. Registering WCF channel as below string serviceUrl = "http://localhost:8000/AdvancedPersonSelectService.svc"; IocContainer.Instance.RegisterType<IPersonAdvancedPersonSelectService, AdvancedPersonSelectService>( new InjectionFactory( c => WcfClientProxyBuilder.CreateProxy<IPersonAdvancedPersonSelectService>(serviceUrl))); IocContainer.Instance is the Unity container wcfClientProxyBuilder returns a WCF channel. Resolving this by var

NullReferenceException with HtmlDocument reference in C#

浪尽此生 提交于 2019-12-13 16:22:07
问题 I am using HtmlAgilityPack in order to scrape information off of Google Translate for a translation program. I have downloaded the HtmlAgilityPack dll, and successfully referenced it in my program. I am using Assembly in Unity. Below is my code for the two programs: using UnityEngine; using System.Collections; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using HtmlAgilityPack; public class GUIScript : MonoBehaviour { private string

How to register same type twice with different constructors in Unity?

烈酒焚心 提交于 2019-12-13 12:10:27
问题 I'm trying to register the same type but with two different constructors. When I trying to resolve, I get " Resolution of the dependency failed " on the second Resolve. var container = new UnityContainer(); container.RegisterType<IBar, Bar>() .RegisterInstance(new Bar()) .RegisterType<IBar, Bar>() .RegisterInstance(new Bar("foo")); Bar bar1 = (Bar)container.Resolve<IBar>(); Bar bar2 = (Bar)container.Resolve<IBar>("foo"); // ERROR What I'm doing wrong? 回答1: You need to give them names when