inversion-of-control

Abstract class or Interface for IoC service?

帅比萌擦擦* 提交于 2020-01-12 05:24:41
问题 I am currently using IoC for providing concrete implemenations of repositories in a project. All of the examples that I have read use an interface as the definition of the service. However, having read recommendations from Microsoft it is recommended to prefer abstract classes over interfaces. I have found this useful in conjuntion with the template pattern to reduce repetition. For example give a Product class with a property IsActive I could use an interface for the repository such as:

ServiceContainer, IoC, and disposable objects

爷,独闯天下 提交于 2020-01-12 03:35:09
问题 I have a question, and I'm going to tag this subjective since that's what I think it evolves into, more of a discussion. I'm hoping for some good ideas or some thought-provokers. I apologize for the long-winded question but you need to know the context. The question is basically: How do you deal with concrete types in relation to IoC containers? Specifically, who is responsible for disposing them, if they require disposal, and how does that knowledge get propagated out to the calling code? Do

Repository pattern with Linq to SQL using IoC, Dependency Injection, Unit of Work

送分小仙女□ 提交于 2020-01-12 02:04:31
问题 There seems to be lots of examples on implementing Repository pattern for Linq to SQL. Most of them featuring IRepository and DI; Some have implemented Unit of Work and some not. I tried to read as most of the results returned by searches on SO and Google on Linq to SQL repository patterns. Nevertheless I've not come across a complete solution yet. From my readings I've implemented a repository pattern as shown below: I'm using DI to register interfaces on which the repositories are depended:

Ninject : Resolving an object by type _and_ registration name/identifier

℡╲_俬逩灬. 提交于 2020-01-11 05:05:07
问题 I am looking for a way to do something like this with Ninject : // Sample from the Unity application block IMyService result = myContainer.Resolve<IMyService>("Data"); ( from http://msdn.microsoft.com/en-us/library/cc440957.aspx ) Is it possible? 回答1: Ninject 2.0 has this capability: Bind<IMyService>().To<MyServiceA>().Named("Data"); Bind<IMyService>().To<MyServiceB>().Named("SomethingElse"); kernel.Get<IMyService>("Data"); // will return MyServiceA 回答2: AFAIK there is no way to do that

How to inject different instance(s) for different context in ASP.NET MVC using StructureMap?

一笑奈何 提交于 2020-01-10 05:49:06
问题 We are using classes inheriting from Registry to configure our StructureMap container in our ASP.NET MVC 4 application startup. Some excerpt from one of the registry-classes: For<ISomeInterface>().HybridHttpOrThreadLocalScoped().Use<SomeImplementation>(); We would like use different instances of our interfaces depending on the context. (For example switching from database "online" mode to "maintenance" mode where everything is saved on filesystem; therefore using other interfaces (i.e.

Examples of IoC Containers [closed]

我的梦境 提交于 2020-01-09 03:01:07
问题 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 . Does anyone have good examples of IoC containers (preferably in c#) and how and why to use them ? I have checked out the wiki page and

Spring dependency injection not completing in time

故事扮演 提交于 2020-01-06 19:26:39
问题 All, I'm setting up a Spring IOC container using dependency injection, etc. I'm running into a very bizarre behavior where it seems that some beans in a collection get fully initialized before use while others don't. The weird part is that all of these beans share the same superclass and the failed dependency injection is happening in one of the superclass dependencies. Here is the example: @Component class Bar { void doSomething() { // do something } } class Foo { @Autowired Bar bar }

Creating Custom Container Class in c#

大城市里の小女人 提交于 2020-01-06 04:53:28
问题 I'm writing a basic c# class for custom IOC container with two Public methods Register() & Resolve() and one private Method CreateInstance() below is my code. In the below Code, CreateInstance() method, i'm getting syntax error to Resolve the dependencies (commented line), without using Generics I could resolve the dependencies and it works fine, while using generics for default typecasting I'm getting syntax error Can anyone help me on this Commented Line? public class Container { static

static methods vs dependency injection for data access layer

十年热恋 提交于 2020-01-06 01:51:26
问题 For my ASP.NET MVC projects, I used to rely heavily on static methods for my data access, kind of like this : public class MyTable { public static IEnumerable<MyTable> findAll() { using (var connection = new SqlConnection(Provider.connString)) { //implementation here } return datas; } public static MyTable find(guid id) { using (var connection = new SqlConnection(Provider.connString)) { //implementation here } } } so i could call them like this in my controller : var datas = MyTable.findAll()

How do i get MEF container to inject himself

早过忘川 提交于 2020-01-05 10:33:25
问题 I'm using constructor injection with MEF Composition Container and I want to know how can I make the CompositionContainer inject itself on the instance of the object he is providing. 回答1: You can use one of the CompositionContainer.ComposeExportedValue methods to create a part from a given object. Here's a sample: class Program { static void Main(string[] args) { var container = new CompositionContainer(new ApplicationCatalog()); Console.WriteLine("Main: container [{0}]", container