inversion-of-control

Swap out repositories with a flag

断了今生、忘了曾经 提交于 2019-12-24 03:18:35
问题 I have an IRepository< T > interface with many T's and several implementations (on-demand DB, web service, etc.). I use AutoFac to register IRepository's for many T's depending on the kind of repository I want for each T. I also have a .NET-caching-based implementation that looks for T's in cache and then calls a 'real' IRepository.Find to resolve a cache miss. It is constructed something like this: new CachingRepository(realRepository, cacheImplementation); I would like to use a

Dependency Injection - Proper use of interfaces? [closed]

六眼飞鱼酱① 提交于 2019-12-24 03:07:59
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I've been reading about DI and best practices, and still haven't found the answer to this question. When should I use interfaces? Some

ReactJS.Net on MVC5 fails to resolve dependency

徘徊边缘 提交于 2019-12-24 02:23:41
问题 I'm trying to set up an ASP.Net MV5 application to work with ReactJS.Net, including server side rendering and bundling. Unfortunately, it fails with this exception: An exception of type 'React.TinyIoC.TinyIoCResolutionException' occurred in React.dll but was not handled in user code Additional information: Unable to resolve type: React.ReactEnvironment This exception occurs on this line: @Scripts.Render("~/bundles/ui-components") This line is taken my _layouts.cshtml file. How should I solve

Dependency Injection - Choose DLL and class implementation at runtime through configuration file

牧云@^-^@ 提交于 2019-12-24 01:53:44
问题 I've an API DLL ( API.dll , for example) which, in addition to many other thinks, makes available an abstract class ( AbstractClass ). Now making use of that AbstractClass I've implemented it on two different dlls: First.API.Implementation.dll with ConcreteImplementation1 Second.API.Implementation.dll with ConcreteImplementation2 Both ConcreteImplementation1 and ConcreteImplementation2 are implementation of the same abstract class. What I want is an application where I can choose which of

Castle Windsor IoC inject Property into Constructor

孤人 提交于 2019-12-24 01:19:41
问题 I have a session manager class that has a session property. I need to pass that into another class as a constructor parameter. How should I configure the installer for castle windsor? e.g. public interface ISessionManager { ISession CurrentSession { get; set; } } public class SessionManager : ISessionManager { private ISession _session; public ISession CurrentSession { get { return _session ?? (_session = NHibernateHelper.OpenSession()); } set { _session = value; } } } public interface

Ioc and WebForms - How to inject properties in user controls

帅比萌擦擦* 提交于 2019-12-23 18:22:45
问题 I am adding IoC to an already existing web forms project, and I am having a little trouble with getting the dependencies of user controls injected, especially dynamic user controls in a master page. On the master page, I load some user controls: protected override void OnLoad(EventArgs e) { bool processComplete = false; var page = Page as BasePage; if (page != null && HttpContext.Current.User.Identity.IsAuthenticated) processComplete = page.processComplete ; var segments = this.Request.Url

UWP Template 10 and Service Dendency Injection (MVVM) not WPF

时光总嘲笑我的痴心妄想 提交于 2019-12-23 15:32:57
问题 I have spent over two weeks searching google, bing, stack overflow, and msdn docs trying to figure out how to do a proper dependency injection for a mobile app that I am developing. To be clear, I do DI every day in web apps. I do not need a crash course on what, who, and why DI is important. I know it is, and am always embracing it. What I need to understand is how this works in a mobile app world, and in particular a UWP Template 10 Mobile app. From my past, in a .net/Asp app I can

UWP Template 10 and Service Dendency Injection (MVVM) not WPF

痞子三分冷 提交于 2019-12-23 15:27:06
问题 I have spent over two weeks searching google, bing, stack overflow, and msdn docs trying to figure out how to do a proper dependency injection for a mobile app that I am developing. To be clear, I do DI every day in web apps. I do not need a crash course on what, who, and why DI is important. I know it is, and am always embracing it. What I need to understand is how this works in a mobile app world, and in particular a UWP Template 10 Mobile app. From my past, in a .net/Asp app I can

Using log4net with Autofac

大兔子大兔子 提交于 2019-12-23 15:26:39
问题 I am trying to use log4net with Autofac. I've pasted this code http://autofac.readthedocs.org/en/latest/examples/log4net.html , and from Program.cs/Main() I am doing var iocBuilder = new ContainerBuilder(); iocBuilder.RegisterModule(new LoggingModule()); var iocContainer = iocBuilder.Build(); now I would like to try this out immediately (in the next line), writing a simple line to the log file. How should I do it? I am thinking of something like this var ls = iocContainer.Resolve

Replace Spring.Net IoC with another Container (e.g. Ninject)

蹲街弑〆低调 提交于 2019-12-23 10:10:23
问题 I'm curious to know if it's possible to replace Spring.Net's built-in IoC container with Ninject. We use Ninject on my team for IoC in our other projects so I would like to continue using that container if possible. Is this possible? Has anyone written a Ninject-Spring.Net Adapter?? Edit I like many parts of the Spring.Net package (the data access, transactions, etc.) but I don't really like the dependency injection container. I would like to replace that with Ninject Thanks 回答1: Jeffrey, can