dependency-injection

autofac scope around a resolved instance

拈花ヽ惹草 提交于 2020-01-06 05:28:11
问题 I'm somewhat new to autofac, but have already used it successfully with different "simple" configurations. Now I'm trying something more complex and struggle with working this out. Essentially, I have an entry point where all autofac configuration is done and the first objects are resolved, which themselves get dependencies by constructor injection, their dependencies can have other dependencies and so on. Some code: public class Root { public Root(A.Factory factory) { for (int i = 0; i < 3;i

Spring Bean implemented by a 3rd party library that uses @Inject conflicting with Spring's injection mechanism

馋奶兔 提交于 2020-01-06 05:25:46
问题 I am trying to have a @Bean implemented by a class from a 3rd party library (OWL API). This implementation uses an @Inject annotation. Spring tries to interpret it, interfering with the injection mechanism of the 3rd party library and avoiding it to work as intended. Is there a way to instruct Spring to ignore the @Inject annotations of the bean implementation, when instantiating the bean? I found few questions about this subject but none of them provided a solution usable in my context. I

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

Faker for Grails gives variable not defined error

∥☆過路亽.° 提交于 2020-01-06 03:42:06
问题 I have a Grails 2.4.4 application configured with spring-security-core. I want to generate fake users in the BootStrap using the faker plugin. However when I instantiate the bean fakerService in BootStrap and try using it ie. fakerService.firstname() , I get an error : ERROR context.GrailsContextLoaderListener - Error initializing the application: Cannot invoke method firstName() on null object Message: Cannot invoke method firstName() on null object I'm just a beginner in Grails. Am I doing

How exactly dependency injection is implemented internally in Spring.net?

你。 提交于 2020-01-06 01:56:37
问题 I'm just curious to know about this.When i heard about Spring.net and tried some sample codes of DI i found it cool and eventually i was curious to know how it works and implemented internally? Even though have the src along with the framework i'm not yet good enough to find out where and how it is done. Is this something to do with Reflection ? (A Dilbert quote here:- "A little knowledge can be too dangerous" :-) ) 回答1: To understand how the basic injection mechanism works, take a look at

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()

When to commit NHibernate Transaction?

这一生的挚爱 提交于 2020-01-05 12:16:13
问题 While very familiar to Webforms and Linq, I am a novice to the ASP.NET MVC and NHibernate World. I have been working through a project using Bob Cravens' examples. My application is mostly reads and non-sequential writes, so typically I would not use a transactions. But to implement the Unit-of-Work pattern, all my research including Ayende's blog says I should. The problem I have is this - Ninject creates a Session and Opens a Transaction. Ninject injects repositories into services, and

When to commit NHibernate Transaction?

我们两清 提交于 2020-01-05 12:16:12
问题 While very familiar to Webforms and Linq, I am a novice to the ASP.NET MVC and NHibernate World. I have been working through a project using Bob Cravens' examples. My application is mostly reads and non-sequential writes, so typically I would not use a transactions. But to implement the Unit-of-Work pattern, all my research including Ayende's blog says I should. The problem I have is this - Ninject creates a Session and Opens a Transaction. Ninject injects repositories into services, and

Binding recurring connection string constructor parameters using DI

巧了我就是萌 提交于 2020-01-05 12:07:16
问题 I'm looking for advice on how best to bind a couple of connection strings which recur throughout my dependencies. Currently I have (using ninject): Bind<IFoo>().To<SqlFoo>() .WithConstructorArgument("db1ConnStr", db1ConnectionString) .WithConstructorArgument("db2ConnStr", db2ConnectionString); Bind<IBar>().To<SqlBar>() .WithConstructorArgument("db1ConnStr", db1ConnectionString) .WithConstructorArgument("db2ConnStr", db2ConnectionString); etc. which obviously is not the most elegant code. Is

Partial injection with Ninject?

自古美人都是妖i 提交于 2020-01-05 11:52:33
问题 I am trying to implement Ninject on an existing class that have a bool parameter in the constructor public MyClass(bool val) //[OPTION 1: Current] { //I Called static function to do something -> I want to inject this ... if(val){ ... } else{ ... } ... } I want to change the logic to inject ISomething .... the ctor will look like: public MyClass(ISomething something, bool val) //[OPTION 2: Desired] { something.DoSomething(); ... if(val){ ... } else{ ... } ... } Also I used a disposable class