unity-container

How to inject dependencies into the global.asax.cs

我是研究僧i 提交于 2019-11-28 17:26:32
问题 How do I inject dependencies into the global.asax.cs, i.e. the MvcApplication class? Having previously used the Service Locator (anti-)pattern for dependency injection, I am trying to follow best practice advice in my latest MVC application by using an IOC container (specifically Unity.Mvc3 because it comes with an implementation of the IDependencyResolver out of the box) and constructor injection. Everything seems quite straight forward so far except for a couple of snags, one of which is in

IoC in class library. Where to bootstrap

丶灬走出姿态 提交于 2019-11-28 17:02:49
I'm using a class library that can be reused by other components. In this class library I'm using unity for dependency injection. For this class library I create a test project. The caller also gets a test project. One thing I'm uncertain about is the location of the bindings. Should I incorporate this in the class library or should I do this from the calling application? This is an interesting problem. How can you dependency inject re-usable assemblies that do not have an entry point. I would really like to see other people's answer. Dependency injection is the responsibility of the entry

Entity Framework using Repository Pattern, Unit of Work and Unity

安稳与你 提交于 2019-11-28 16:22:23
问题 Using a combination provided from this example and this implementation I am trying to create a solution that decouples the UnitOfWork class from the individual repositories, as they violate the Open-Closed Principle, since every time you added a new repository you would have to modify the UnitOfWork class. I am using Unity as the IoC container to wire up dependencies. The problem I have is that in automatically wiring up the UnitOfWork , IDbContext and the repositories ( IEmployeeRepository

Getting Started with Unity Framework [closed]

泄露秘密 提交于 2019-11-28 15:52:28
问题 Could anyone recommend some good resources for getting started with the Unity framework? I've downloaded the source from Codeplex and got it to compile. So now I've got a set of compiled binaries, where do I go next? I understand the principles of inversion of control but don't have much knowledge of the specifics of the Unity framework. I've downloaded the Unity documentation from Codeplex but it seems to be targeted at users that already have a good working knowledge of the framework. What

Proper way to Mock repository objects for unit tests using Moq and Unity

£可爱£侵袭症+ 提交于 2019-11-28 15:48:26
At my job we are using Moq for mocking and Unity for an IOC container. I am fairly new to this and do not have many resources at work to help me out with determining the best practices I should use. Right now, I have a group of repository interfaces (Ex: IRepository1, IRepository2... IRepository4) that a particular process needs to use to do its job. In the actual code I can determine all of the IRepository objects by using the IOC container and using the RegisterType() method. I am trying to figure out the best way to be able to test the method that needs the 4 mentioned repositories. I was

MVVM Light + Unity or Prism?

人盡茶涼 提交于 2019-11-28 15:15:14
I am a little out-of-date in WPF right now and would be interested to hear peoples opinions on the latest version of Prism (which I used a couple of versions ago) vs an MVVM Light + Unity approach (which I have never done - decent examples URLs would be good). My project will be a large one comprising multiple modules written by several developers. There is also the funds to bring in a 3rd party control suite in order to set up a nice workspace using one of the fancy Docking/Workspace layout managers out there (and I know some play better with the Prism regions than others). If you were

IUnityContainer.Resolve<T> throws error claiming it cannot be used with type parameters

社会主义新天地 提交于 2019-11-28 15:07:53
问题 Yesterday I've implemented the code: CustomerProductManager productsManager = container.Resolve<CustomerProductManager>(); It was compilable and working. Today (probably I've modified something) I am constantly getting the error: The non-generic method 'Microsoft.Practices.Unity.IUnityContainer.Resolve(System.Type, string, params Microsoft.Practices.Unity.ResolverOverride[])' cannot be used with type arguments My collegue has the same source code and doesn't have same error. Why? How to

What is different between and purpose of MEF and Unity?

浪子不回头ぞ 提交于 2019-11-28 14:44:07
问题 I just start study DI (I'm working on WPF/Silverlight but I have a plan to move to ASP.NET). After I read some DI articles from internet there are two Frameworks that I'm interested in, MEF and Unity. I want to know what is the real-world different between them and which one is good to go. 回答1: The main difference is that with unity you will explicitly register each class you want to use in the composition: var container = new UnityContainer(); container.RegisterType<IFoo,Foo>(); container

Unity.MVC4 lazy<T> is not working in ASP.NET MVC app

僤鯓⒐⒋嵵緔 提交于 2019-11-28 12:39:36
I am using ASP.NET MVC 4 application. Home controller’s constructor is parameterized with 2 parameter(Iservice1 service1, Iservice2 service2) Not all the code path uses any of the Service (service1, service2), only in some code path I need service1 instance/object or service2 instance/object. I don’t want to use container.Resolve< <Lazy<IService1> >(); From this link ( http://msdn.microsoft.com/en-us/library/dn178463(v=pandp.30).aspx ) I understood that unity.mvc 4 use unity 3 which has Lazy loading support, but how to do this in ASP.NET MVC 4. In general, instance constructors should do

Using Unity, how do you register type mappings for generics?

送分小仙女□ 提交于 2019-11-28 12:07:36
I'm trying to implement a repository solution for Entity Framework but I am having trouble registering the types that include generics using Unity. Given: // IRepository interface public interface IRepository<TEntity> { // omitted for brevity } // Repository implementation public class Repository<TEntity, TContext> : IRepository<TEntity>, IDisposable where TEntity : class where TContext : DbContext { // omitted for brevity } // service layer constructor public MyServiceConstructor(IRepository<Account> repository) { _repository = repository; } I need to register the type mapping for IRepository