unity-container

split unity configuration file

柔情痞子 提交于 2019-12-10 18:08:12
问题 I need to split my unity configuration into n different files so i can select it some of those files into the same unity container?? 回答1: OK. It's too late but I could answer. You need something like this: private IUnityContainer ReadContainer() { var unityCommon = (UnityConfigurationSection)ConfigurationManager.GetSection("unityCommon"); IUnityContainer returnValue = new UnityContainer(); unityCommon.Configure(returnValue, "Common"); // Unnamed <container> element var unitySpecific =

Unity and delegate

情到浓时终转凉″ 提交于 2019-12-10 17:46:09
问题 I'm using the Unity dependency injection framework. I have two classes, that each take the same delegate parameter in the constructor. Each class should get a different method when resolved. Can I set this up without using attributes ? If not how would you do it with attributes? 回答1: Yep, you can decorate properties or constructor parameters with the [Dependency] attribute. This example isn't using delegates, it's just using an interface instead, but it shows two of the same interface being

Unity & WPF - injecting a DataContext via property injection to a child control

坚强是说给别人听的谎言 提交于 2019-12-10 16:19:59
问题 I followed Jason Dollinger's MVVM sample from Lab49 to learn the basics of using Unity with an MVVM WPF application. I constructed a simple sample following his basic architecture, using property injection and the Dependency attribute to inject viewmodels into the views. My sample has a main window with a child user control created in the window's XAML. The child control (and the main window, too) has a property for assigning the viewmodel: [Dependency] public IChildViewModel VM { set { this

Unity - Factory via XML

…衆ロ難τιáo~ 提交于 2019-12-10 15:52:12
问题 I am using the Unity framework as IoC container. My Config looks some like this: <unity> <container> <register type="Namespace1.IFoo, FooAsm" mapTo="Namespace2.Bar, BarAsm"> </register> </conainer> I would like to register a container to use a factory method. How do i achive it using the app.config? I am looking for something like this: <unity> <container> <register type="Namespace1.IFoo, FooAsm" factory="Namespace2.Bar, BarAsm" method="create"> </register> </conainer> </unity> Any

How to register types in the main container, but resolve in a child container?

梦想的初衷 提交于 2019-12-10 15:51:27
问题 I have a unity container and use RegisterType to register the following repository and implementer using ContainerControlledLifetimeManager . public interface IPersonRepository { Person GetByID(ObjectSpace objectSpace, int id); } Using this pattern I am able to have multiple threads (it's a web app) using the same repository instance at the same time despite the fact that each thread is using a different ObjectSpace (which is a local cache + mechanism for fetching objects from the DB + a unit

Unity Error: The given assembly name or codebase was invalid

感情迁移 提交于 2019-12-10 15:28:24
问题 I am using the microsoft unity frame work and getting this error: ********** 4/15/2012 9:46:08 AM ********** Inner Exception Type: System.IO.FileLoadException Inner Exception: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Inner Source: mscorlib Inner Stack Trace: at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName,

How to register an AutoMapper profile with Unity

試著忘記壹切 提交于 2019-12-10 15:27:06
问题 I have the following AutoMapper profile: public class AutoMapperBootstrap : Profile { protected override void Configure() { CreateMap<Data.EntityFramework.RssFeed, IRssFeed>().ForMember(x => x.NewsArticles, opt => opt.MapFrom(y => y.RssFeedContent)); CreateMap<IRssFeedContent, Data.EntityFramework.RssFeedContent>().ForMember(x => x.Id, opt => opt.Ignore()); } } And I am initializing it like this: var config = new MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperBootstrap()); });

XML config changes in Unity 2.0

[亡魂溺海] 提交于 2019-12-10 14:48:01
问题 we've just upgrade a project from prism 2.0 to prism 4.0, and we're having problems with Unity. Apparently there's several changes in unity 2.0 container XML configuration as we get as our first error " Unrecognized element 'typeConfig' ". Here is the code: //----------------------- App.config <configSections> <section name="runDataParserConfiguration" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" /> </configSections>

Full stack trace for intercepted methods at call site in Unity

眉间皱痕 提交于 2019-12-10 14:21:20
问题 We're looking into using Unity to handle logging service methods with interception. However, one concern is that the full stack trace is not available at the call site; its only available within an interceptor call. Here's an example setup: public interface IExceptionService { void ThrowEx(); } public class ExceptionService : IExceptionService { public void ThrowEx() { throw new NotImplementedException(); } } public class DummyInterceptor : IInterceptionBehavior { public IEnumerable<Type>

Unity/Caliburn Micro, Injection Constructor with multiple parameters

China☆狼群 提交于 2019-12-10 11:57:27
问题 I am currently trying to learn how to implement MVVM using Unity and Caliburn Micro. After looking around for help elsewhere I am still unsure about how to set up the Constructor Injection properly. I don't know if this is not working due to my lack of expertise in MVVM or something else. My problem is I want to pass in two IScreen Objects into my main window(shell) Class that can be navigated between when the user clicks on a button. Here is the code for the constructor in my