unity-container

“The underlying provider failed on Open” Error when using EF5 Code First with Unity IoC in Azure Worker Role against SQL Azure

回眸只為那壹抹淺笑 提交于 2019-12-24 09:36:10
问题 I am using Entity Framework 5 Code First, I use the repository and unit of work pattern, and have my domain models, repositories, and service layer working fine within an MVC app running in a Windows Azure cloud service. I'm using Unity for IoC and inject repositories, controllers, and service classes as required, and use a per-request lifetime. It has been working great. However, when I use the same code/class libraries for the domain, repository, and the EF5 DbContext, in an Azure Worker

Using DI to add Interceptor to NHibernate Sessions in legacy code

若如初见. 提交于 2019-12-24 08:51:10
问题 So, there's a bug in some legacy code I'm maintaining. It causes some mild data corruption, so it's rather serious. I've found the root cause, and have made a sample application that reliable reproduces the bug. I would like to fix it with as little impact on existing applications as possible, but I'm struggling. The bug lies in the data access layer. More specifically, in how an interceptor is injected into a new Nhibernate Session. The interceptor is used to set a specific entity property

In asp.net MVC2 using unity does my program need to manage the lifetime of the container?

浪子不回头ぞ 提交于 2019-12-24 07:46:12
问题 I'm putting the unity container creation/setup in the global.asax. and making the container a static property on that class since i'm not sure how unity works or if the container needs to be kept alive and references elsewhere. What's the recommended location of unity initialization/configuration for mvc 2? 回答1: You shouldn't need to keep an explicit reference around for the container. A container should wire up the requested object graph (Controllers in this case) and get out of the way.

Resolve may fail depending on order of RegisterInstance and RegisterType

只愿长相守 提交于 2019-12-24 07:34:57
问题 When using this object model: interface IInterface {} class Impl : IInterface { public Impl(int blah) {} } And this test: void Test1() { IUnityContainer container = new UnityContainer(); container.RegisterInstance(new Impl(3), new ContainerControlledLifetimeManager()); container.RegisterType<IInterface, Impl>(new ContainerControlledLifetimeManager()); Impl impl = container.Resolve<Impl>(); } I get an exception: Resolution of the dependency failed, type = "BlahMain.Program+Impl", name = "(none

With unity and generics, are instances of closing types injected during the spinning up of the container and if so why?

百般思念 提交于 2019-12-24 07:13:40
问题 It appears this is the case. If I am marking a generic as a closed type, I am stating my intention to use a Type and not an Instance of a Type. I am getting an error as Unity is trying to resolve the closing type in the ExternalLinkingRepository class below. The error states that Unity can not reconcile the constructor as there is more than 1 with the same number of parameters (2). I have looked at constructor injectors (and indeed need one for the connection string, but this is not the issue

Unity 1.2 Dependency injection of internal types

孤街浪徒 提交于 2019-12-24 07:02:12
问题 I have a facade in a library that exposes some complex functionality through a simple interface. My question is how do I do dependency injection for the internal types used in the facade. Let's say my C# library code looks like - public class XYZfacade:IFacade { [Dependency] internal IType1 type1 { get; set; } [Dependency] internal IType2 type2 { get; set; } public string SomeFunction() { return type1.someString(); } } internal class TypeA { .... } internal class TypeB { .... } And my website

Inject custom code in standard application

笑着哭i 提交于 2019-12-24 07:00:12
问题 We have a standard application in our company. Now I want to inject some custom assemblies in the application. Normally if you have a ninject kernel or unity container, you can get the implementation like below: IKernel kernel = new StandardKernel(); DealerService myServ = new DealerService(kernel.Get<IDealerController>()); DealerService: public partial class DealerService : ServiceBase { private readonly IDealerController Controller; public DealerService(IDealerController controller) {

Creating WPF ResourceDictionary from code doesn't seem to work when setting ResourceDictionary.Source

眉间皱痕 提交于 2019-12-24 06:39:12
问题 I have a project containing a xaml ResourceDictionary that I wish to use outside of a FrameworkElement. The resource dictionary will contain a DataTemplate for a class local to the project to avoid polluting the app.xaml (as the project is a prism module, and will not always be present depending on config). So, I have a test.xaml file with a Resource build action. This is intended to supply the DataTemplate for a TestObject class. In the TestObject class I have a GetTemplate() method The

.Net Dependency injection in unit of work pattern using repositories

一曲冷凌霜 提交于 2019-12-24 04:23:09
问题 I'm a relative noob to the concept of Dependency Injection, and have been trying to glean the best practices before starting a new project. Looking at the top answer to Dependency injection in unit of work pattern using repositories I understand the approach, but the example code seems to be missing something, and I'm stumped... The definition of the interface IRepository is shown as: public interface IRepository { void Submit(); } But when the interface is used as part of the definition of

Solving multiple interface implementation

天涯浪子 提交于 2019-12-24 03:12:19
问题 I am in this situation where my service interface is being implemented by two service classes. For example, IFooService is implemented by FooService and FooWithExtraInfoService Here is the interface: public interface IFooService { Foo GetEntity(string fieldName, stringFieldValue); } Here is FooService : public class FooService: BarService, IFooService { public FooService(ILogService logservice): base(logservice) { } public Foo GetEntity(string fieldName, string fieldValue) { //here goes the