unity

ViewModel communication question

Imagine I have a UserControl that shows a parking lot (my favorite analogy) with cars of different colors. You can select a car, and in a separate UserControl (in a separate project) statistics of the selected car are displayed. Now a user wants a button on the car statistics UC, 'Next car of same color'. When selected it should show ...

Using Unity, How do I autoregister a generic class with a generic interface without registering EVERY type to it.

I am using Unity and Unity.AutoRegistration. This line for Unity: unityContainer.RegisterType(typeof(IAction<>), typeof(Action<>)); effectively registers every class in the project to IAction/Action: unityContainer.RegisterType<IAction<ObjectA>, Action<ObjectA>>(); unityContainer.RegisterType<IAction<ObjectB>, Action<ObjectB>>(); uni...

Dependecy Injection: How To Overcome Cyclic Dependencies

Hello guys, Thanks for reading. I'm using Unity framework to implement dependency injection in my app (ASP.Net MVC). Sometimes there are some cyclic dependencies among services that I want to avoid. So I'm looking for solutions : ) My case well lets imagine 3 services ServiceSally, ServiceJoe, ServiceJudy ServiceSally depends on S...

How do I convert this WindsorControllerFactory to a UnityControllerFactory in either VB.NET or C#

I have been following along in the book Pro ASP.NET MVC Framework by Steven Sanderson. I am trying to rewrite an application to use Unity IoC instead of Castle Windsor IoC. I want the Unity implementation to register all of the controllers like the Windsor one does. Here is the WindorControllerFactory code: public class WindsorContro...

How can I reduce the amount of configuration needed in .config for Unity dependency injection?

I've got dependency injection working with Unity and it runs nicely but I want to reduce the amount of cruft in the app.config as it is getting huge. This is an issue because the customer routinely 'cleans up' the config by removing comments etc and we end up with a few hundred lines of nasty XML without explanation. So, is there a way...

WPF unity Activation error occured while trying to get instance of type

I am getting the following error when trying to Initialise the Module using Unity and Prism. The DLL is found by return new DirectoryModuleCatalog() { ModulePath = @".\Modules" }; The dll is found and the Name is Found #region Constructors public AdminModule( IUnityContainer container, IScreenFactoryRegistry...

Unity performance considerations with container controlled lifetime - Is there any reflection lag with multiple Resolve<T>() calls?

Is there any reflection performance considerations when repeatedly calling container.Resolve<T>() when a resolution has already been established? I'm using it in an MVC controller to resolve my data service, so it will be called on every HTTP request. I'm storing the container instance in Application state, and I'm using container contr...

Unity and MVVM. Class fields become null

Hello! My application is pretty complex, so even simplified example would be complex enough. So I'll try to point some its fundamentals and the problem itself. It is an MDI application. MDI is of custom implementation since there is no native MDI in WPF. The problem is in main container window. It is called Shell and as it is an MVVM ap...

GetControllerInstances type is null

Hello, Try to ASP.NET MVC 2 Areas and have a problem. I have a User Area and a Blog area. User area is working properly but when I use my Blog area the controllerType is null in my GetControllerInstance. I have not made any changes in my areas so everything is as it was when I created them. I Have also tried to add a test area with name ...

Unity IOC container and how to resolve different instances of the same interface

I have a unity container that I am registering types within like so: IUnityContainer container = new UnityContainer() .RegisterType<ITaxAuthorityRateService, TaxAuthorityPopulationRateService>( "PopulationRate" ) .RegisterType<ITaxAuthorityRateService, TaxAuthorityBusinessLicenseRateService>( "BusinessLicenseRate" ); Then I also w...

Unity configuration problem

I'm currently have a Could not load ExternalIdentityProvider when i tried to run my ioc class container = new UnityContainer(); UnityConfigurationSection unitySection = ConfigurationManager.GetSection(unitySectionName) as UnityConfigurationSection; unitySection.Containers.Default.Configure(container); Could not load type 'ExternalIden...

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

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 voi...

Multi tenancy with Unity

Hi everybody! I'm trying to implement this scenario using Unity and i can't figure out how this could be done: the same web application (ASP.NET MVC) should be made accessible to more than one client (multi-tenant). The URL of the web site will differentiate the client (this i know how to get). So getting the URL one could set the (l...

What is the best way to integrate Dependency Injection using Unity when static methods are used?

Hi All, Im faced with an impending upgrade to an ASP.NET site and I am thinking of introducing DI using Unity. I have researched the ASP.NET DI side of things and have 2 options (Global.asax or IHttpModule). Im happy to use either. As always, there is a legacy object model in place that I would like to upgrade/change. I would like t...

Finding the angle of a fleeing dodo.

I'm coding some critter AI for a game i am working on for my Unity 3D project. I have no programming background and have been stumbling through this using tutorials and other peoples scripts. My problem is that i want my critter to run directly away from the player when the player kicks it. I need the dodo to run directly away from the...

Injecting an IPrincipal with Unity Property Injection at runtime

Using Unity in an ASP.Net MVC 2 app I have various dependencies on Controllers instantiated correctly. However, I want to ensure that the current IPrincipal for the user is going to be passed via injection to lower level Services, Repository etc. Therefore in a lower level service I have something like: [Dependency] IPrincipal Current...

Unity framework - reusing instance

nobody loved my first question about this: http://stackoverflow.com/questions/2407636/creating-entity-framework-objects-with-unity-for-unit-of-work-repository-pattern so I've managed to rephrase it to something you can read without falling asleep/losing the will to live. I'm creating an object, DataAccessLayer, that takes 2 interfaces ...

Configure Unity for Inherted Interfaces

I am fairly new to Unity, (well, IoC and DI in general), and am having problems configuring it for my use. I have two interfaces: public interface ISample { ... } and public interface IDerivedSample : ISample { ... } and a number of concreate classes simular to: public class UseSample : IDerivedSample { ... } I am attempting to...

Using Unity and interfaces, how do I create a concrete class that implements IDisposable

I have an interface (IDbAccess) for a database access class so that I can unit test it using Unity. It all works fine in Unity and now I want to make the concrete database class implement IDisposable so that it closes the db connections. My problem is that Unity does not understand that my concrete class is disposable because the interf...

Getting error "Association references unmapped class" when using interfaces in model

I'm trying to use the automap functionality in fluent to generate a DDL for the following model and program, but somehow I keep getting the error "Association references unmapped class: IRole" when I call the GenerateSchemaCreationScript method in NHibernate. When I replace the type of the ILists with the implementation of the interfaces...