dependency-injection

Dependency Injection in ASP.net Session_Start method

我的梦境 提交于 2019-12-22 09:25:54
问题 I am learning dependency injection and using autofac for the first time. I built the container as mentioned in several autofac examples (see below) and called from my application_start public class ContainerConfig { public static void RegisterContainer() { //Create a new ContainerBuilder var builder = new ContainerBuilder(); // Register all the controllers using the assembly object builder.RegisterControllers(Assembly.GetExecutingAssembly()); //Registering default convention -- IExample and

DbContext is Disposed When Using Unity Dependency Injection on WebApi project

佐手、 提交于 2019-12-22 09:25:33
问题 I'm fairly new at using dependency injection and I think I must be overlooking something really simple. I have a Web API project where I'm registering generic repositories. The repositories take a dbContext as a parameter in their constructor. The behavior I find strange is that I can make one successfull call to the service but any subsequent calls tell me that the dbcontext has been disposed. I do have a using statement in there but that shouldn't be a problem since DI is supposed to be

Using Spring's LocalValidatorFactoryBean with JSF

戏子无情 提交于 2019-12-22 09:23:40
问题 I am trying to get a bean injected into a custom ConstraintValidator . I have come across some things: CDI is supported in validation-api-1.1.0 (Beta available) Hibernate Validator 5 seems to implement validation-api-1.1.0 (Alpha available) Use Seam validation module Use Spring's LocalValidatorFactoryBean The last one seems most appropriate for my situation since we're already using Spring (3.1.3.Release). I have added the validator factory to the XML application context and annotations are

Using Spring's LocalValidatorFactoryBean with JSF

折月煮酒 提交于 2019-12-22 09:23:15
问题 I am trying to get a bean injected into a custom ConstraintValidator . I have come across some things: CDI is supported in validation-api-1.1.0 (Beta available) Hibernate Validator 5 seems to implement validation-api-1.1.0 (Alpha available) Use Seam validation module Use Spring's LocalValidatorFactoryBean The last one seems most appropriate for my situation since we're already using Spring (3.1.3.Release). I have added the validator factory to the XML application context and annotations are

How to use DI when spawning new Windows Forms downstream?

帅比萌擦擦* 提交于 2019-12-22 08:57:17
问题 I have the Unity DI container working initially with my Windows Forms application. In Program.cs I have the following: static void Main() { var container = BuildUnityContainer(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(container.Resolve<MainForm>()); } private static IUnityContainer BuildUnityContainer() { var container = new UnityContainer(); container.RegisterType<ITest, MyTestClass>(); container.RegisterType<ISomeOtherTest,

“An MVC filter provider has already been registered for a different Container instance.” in Simple Injector 2.6

独自空忆成欢 提交于 2019-12-22 08:57:10
问题 I previously had the setup for property injection in one of my attributes as Container.RegisterInitializer<PermitAttribute>(initialize => { initialize.QueryProcessor = Container.GetInstance<IQueryProcessor>(); }); And the usage was public class PermitAttribute : ActionFilterAttribute { public IQueryProcessor QueryProcessor { get; set; } } but after updating to simpleinjector 2.6.1 The property injection broke. When I am trying to access QueryProcessor object inside PermitAttribute. It

How to unit test instance creation?

主宰稳场 提交于 2019-12-22 08:56:11
问题 I have a Carpenter class that does it's work using a Lathe and a Wood object. class Carpenter { function Work() { $tool = new Lathe(); $material = new Wood(); $tool->Apply($material); } } Lathe depends on an interface called Material , so I can easily unit test Lathe by giving it a fake Material in my unit test. Wood doesn't depend on anything, so it can also be easily tested. interface Material { // Various methods... } interface Tool { function Apply(Material $m); } class Wood implements

Dependency Injection - Does it violate Separation of Concerns?

☆樱花仙子☆ 提交于 2019-12-22 08:54:44
问题 Does Dependency Injection violate the Separation of Concerns as it pertains to an n-tier architecture? Suppose you have the following projects: MyApp.Data MyApp.Business MyApp.Web If I were to use DI to tell the Business Layer which Data Context to use, wouldn't this violate SoC? This would mean the UI (MyApp.Web) would have to have knowledge of the Data Access Layer (MyApp.Data) to tell the Business Layer (MyApp.Business) which context to use, right? public class WebForm { public void Save

Dependency Injection - Does it violate Separation of Concerns?

邮差的信 提交于 2019-12-22 08:54:09
问题 Does Dependency Injection violate the Separation of Concerns as it pertains to an n-tier architecture? Suppose you have the following projects: MyApp.Data MyApp.Business MyApp.Web If I were to use DI to tell the Business Layer which Data Context to use, wouldn't this violate SoC? This would mean the UI (MyApp.Web) would have to have knowledge of the Data Access Layer (MyApp.Data) to tell the Business Layer (MyApp.Business) which context to use, right? public class WebForm { public void Save

Android Dagger 2 Dependency not being injected

好久不见. 提交于 2019-12-22 08:53:44
问题 i'm trying to use Dagger 2 into my apps but i'm having some problems regarding the entities repository and i haven't figured it out what i'm missing. Here is my Application Component: @Singleton @Component( modules = { AndroidModule.class, RepositoryModule.class } ) public interface ApplicationComponent { void inject(AndroidApplication app); IDependenceyRepository dependencyRepository(); } My modules: @Module public class RepositoryModule { @Provides @Singleton IDependenceyRepository