I am working on a project where the Unity framework is used as the IoC container. My question relates to injecting an optional dependency (in this case a logger) into several classes using property- or setter injection.
I do not want to clutter the constructors of all my classes with these optional dependencies, but I cannot find a goo...
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...
Howdy,
I am new to using Unity and IoC/DI concepts. I started with the concept by rolling my own via James Kovacs' show on dnrTV in a test.
His example had the Container run as a singleton accessed through a static method in an IoC class so you could register types at a startup and resolve the type throughout your application.
...
I'm using Unity to resolve types dynamically for a pluggable architecture. I'm also using interception to apply business rule validation via AOP (using ValidationAspects). Finally, I'm using NHibernate as an ORM to persist domain objects.
In order for AOP to work, we use the VirtualMethodInterceptor, as interface interception doesn't wo...
Hi,
I'm trying to use a generic custom collection interface (to support injection with Microsoft Patterns and Practices Unity) in a class O/R mapped with iBATIS.NET. Does anyone know if this is possible and if so how to do it?
I have an IDataItemCollection<T> interface that I map to SqlDataItemCollection<T> which extends CollectionBas...
I have a WCF service that is setup to be hosted within a unity container. I was intending to use this container to perform method interception. The only issue is I can get my interceptor to fire...
first here the def of my interceptor attribute and handler
[AttributeUsage(AttributeTargets.Method)]
public class PCSecurityAttribute : H...
I've been reading the articles on MSDN about Unity (Dependency Injection, Inversion of Control), but I think I need it explained in simple terms (or simple examples). I'm familiar with the MVPC pattern (we use it here), but I just can't really grasp this Unity thing yet, and I think it's the next step in our application design.
...
I'm trying the following in Unity:
I have a type with the following constructor
public Type1(Type2 firstDependency, Type3 secondDependency)
When resolving Type1 using Unity, I want to specify the specific instance for Type2 to inject. This specific instance of Type2 is not registered in the container. Type3 is registered in the conta...
This link for unity framework on msdn states
"You want to be able to cache or persist the dependencies across postbacks in a Web application"
http://msdn.microsoft.com/en-us/library/dd203319.aspx#
I am not sure what all the above statement means.
I am looking for an example how we can do this using Unity - not sure how Unity will resol...
(from the StockTraderRIBootstrapper.cs file in the Prism V2 StockTrader example app)
What is the difference between this:
ShellPresenter presenter = new ShellPresenter();
and this:
ShellPresenter presenter = Container.Resolve<ShellPresenter>();
I understand the second example is treating the container like a factory, walking up t...
I'm using Unity for dependency Injection. This seems to help when I'm testing my objects because I can mock out all dependencies. However, how am I supposed to test that my configuration is valid?
For example, I change the Unity configuration in the app.config, and of course, the project will build fine. My tests are currently only test...
I have one interface with 2 classes implementing it, I need to load each class but unity has:
m_unityContainer.Resolve() // Where is the interface IGeneric
my config looks like:
<type type="IGeneric" mapTo="ClassA">
</type>
<type type="IGeneric" mapTo="ClassB">
</type>
any ideas?
thanks
...
I'm trying to Mock the IUnityContainer using Moq 3.0
I'm getting a BadImageFormatException, but not when debugging. From the looks of it I'm not the only one that's ran into this problem.
here
And its a registered issue for Moq
here
I'm just curious if anyone has found a solution... closest I've found is a nice solution that uses Rh...
I'm working with the Composite Application Library and I come across e.g. this line:
Shell shell = Container.Resolve<Shell>();
so I want to look at the code that makes up the Resolve method.
So I open up CompositeApplicationLibrary_Desktop.sln in Visual Studio.
I find classes such as UnityBootstrapper.cs, but nowhere can I find the ...
Unity's documentation says of the RegisterInstance<> method that registers an instance so that that particular instance is returned everytime Resolve<> is called.
However, this example below shows that each time Resolve<> is called, a new instance of the type is returned.
Why is this?
using System;
using System.Windows;
using Microso...
The Unity documentation states:
if a class that developers instantiate
using the Resolve method of the Unity
container has a constructor that
defines one or more dependencies on
other classes, the Unity container
automatically creates the dependent
object instance specified in
parameters of the constructor
This is gre...
I am using Unity with Silverlight and Prism 2. On my laptop (running Vista 32) I am seeing the following error in the output window in VS.NET 2008 SP1 - which I think is being caught internally by Unity.
A first chance exception of type 'System.Threading.SynchronizationLockException' occurred in Microsoft.Practices.Unity
On my desktop ...
I'm trying to figure out how to register a type at run-time using unity. Any Suggestions?
Basically I want to be able to do this:
Container.
RegisterType(Of IMyInterface)(
Type.GetType("Fully Qualified Type Name"))
...
Using the adapter pattern, combined with IoC (specificly Unity), I would like to create a new instance of a object of which the properties point back to the adaptee's propeties (basicly mapping the adaptee to a target object).
As a example I have the following class structures:
public class Adaptee
{
private Adaptee() { }
publ...
I am considering using Unity to manage the lifetime of a custom user class instance. I am planning on extending the LifetimeManager with a custom ASP.NET session manager. What I want to be able to do is store and retrieve the currently logged in user object from my custom classes, and have Unity get the instance of User from the sessio...