inversion-of-control

ASP.NET MVC - Sharing Session State Between Controllers

大兔子大兔子 提交于 2019-12-04 23:05:40
问题 I am still mostly unfamiliar with Inversion of Control (although I am learning about it now) so if that is the solution to my question, just let me know and I'll get back to learning about it. I have a pair of controllers which need to a Session variable, naturally nothing too special has happen because of how Session works in the first place, but this got me wondering what the cleanest way to share related objects between two separate controllers is. In my specific scenario I have an

Castle Windsor resolving and generics

不想你离开。 提交于 2019-12-04 22:31:43
问题 I have the following: public interface ISubject { ... } public class Subject<T> : ISubject { ... } public class MyCode<T> { ... pulic void MyMethod() { var item = container.Resolve<ISubject>(); //????? how do I pass in T } ... } In this case how do i do the resolve. Cheers Anthony 回答1: vdhant - That's not how containers are meant to be used. You want to use ISubject , right?. Then if you passed T you're breaking your abstraction, because your caller must know that ISubject , is actually a

Constructor Dependency Injection in Base Class

限于喜欢 提交于 2019-12-04 19:28:59
问题 i'm building a repository base class with Entity Framework where all Entities repository will inherit. I want to inject the DatabaseContext in base class using Dependency Injection using Ninject. I think the Constructor Injection is the right way, but doing this with Constructor Injection in derived class I will must to pass parameter to constructor in base class and I don't want it. Therefore, a Setter Injection is more appropriate? Here's my code: public abstract class BaseRepository

spring ioc injecting concrete implementation of interface to test

南楼画角 提交于 2019-12-04 19:27:11
I have the following setup: @Component public class ImplOne implements IFace{ } @Component public class ImplTwo implements IFace{ } public interface IFace{ } I am trying to get a reference of ImplOne by type: @RunWith(SpringJUnit4ClassRunner.class) public class ImplOneTest { @Autowired private ImplOne impl; @Test public void test(){ Assert.assertNotNull(impl); } } Though with this I get the following exception: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [some.package.TestBean] found for dependency: expected at least 1 bean which qualifies as

Explain the mysterious world of IoC and automatic Dispose

有些话、适合烂在心里 提交于 2019-12-04 19:18:09
I'm ASP.NET MVC newbye and I'm learning and experimenting Enterprise design patterns: very interesting and helpful things indeed! But I keep missing something about the concept of disposing resources. To be more specific want to focus on the mechanism of controllerFactory which injects in the controller constructor an implementation of IFuncyRepository or IFuncyService or anyother kind of "resource" to be used in the controller (In my case I'm using StructureMap as IoC). My question is WHERE / IF / HOW these injected resources get Disposed. The book I'm following as guideline is ASP.NET Design

Register Container Itself Using Autofac

♀尐吖头ヾ 提交于 2019-12-04 18:28:31
问题 I was wondering is there's any side effect to registering the container within itself IContainer container; ContainerBuilder builder = new ContainerBuilder(); container = builder.Build(); builder.RegisterInstance(container).As<IContainer>(); and the using it like this builder.RegisterType<IManagmentServiceImp>().As<ManagmentServiceImp>() .WithParameter(new ResolvedParameter( (pi, ctx) => pi.ParameterType == typeof(IContainer) && pi.Name == "Container", (pi, ctx) => container )); or whether it

IoC/DI frameworks with Smart Client Winform apps: How should I approach this?

自古美人都是妖i 提交于 2019-12-04 17:55:00
问题 I'm starting a new Winforms app, and I intend to use an IoC/DI framework (probably Ninject, but I'm also thinking about StructureMap and LinFu). It seems like nearly everyone who is using IoC/DI is doing so in a web based environment and have found virtually nothing on using Winforms with it. I'd like to know if anyone is using IoC/DI with Winforms and what approaches you used to deal with Winforms related issues (for instance, how do you make the container available in various parts of the

Dependency Injection for Handlers and Filters in ASP.NET Web API

≯℡__Kan透↙ 提交于 2019-12-04 17:47:59
问题 I am trying to wire up my Web Api project to use Castle Windsor for IoC I have done that for my controllers by following this excellent article. I am now trying to get dependencies injected into my DelegatingHandler and ActionFilterAttribute I have tried to copy the techniques used for filters in regular ASP.Net MVC but they don't seem to apply in Web Api has anyone managed to get this working? I'm not sure what the relevant extension point is in the Web Api I have seen this being suggested

Reuse same instance of prototype bean twice - Spring

我们两清 提交于 2019-12-04 17:06:30
I have a problem with Spring: I need to reuse the same instance of bean twice, but not making it singleton. Here is a brief ApplicationContext: <bean class="a.b.c.Provider" id="defaultProvider" scope="prototype"> <constructor-arg ref="lifecycle" /> <constructor-arg ref="propertySetter" /> </bean> <bean name="lifecycle" class="a.b.c.Lifecycle" scope="prototype"> <constructor-arg ref="someParam" /> ... and more args </bean> <bean id="propertySetter" class="a.b.c.PropertySetter" scope="prototype"> <constructor-arg ref="lifecycle" /> </bean> So, I need to have fully initialized Provider with

What should be the strategy of unit testing when using IoC?

亡梦爱人 提交于 2019-12-04 16:22:40
问题 After all what I have read about Dependency Injection and IoC I have decided to try to use Windsor Container within our application (it's a 50K LOC multi-layer web app, so I hope it's not an overkill there). I have used a simple static class for wrapping the container and I initialize it when starting the app, which works quite fine for now. My question is about unit testing. I know that DI is going to make my life much easier there by giving me the possibility of injecting stub / mock