dependency-injection

ICallHandler, is an interface and cannot be constructed

别等时光非礼了梦想. 提交于 2020-01-16 07:50:20
问题 At code below I got the error : ICallHandler, is an interface and cannot be constructed when resolving the object var attributePolicy = new AttributeDrivenPolicy(); var rulePolicy = new RuleDrivenPolicy("LoggingFlyGoreJumpSleepMethodPolicy", new IMatchingRule[] { new MemberNameMatchingRule(new string[] { "Fly", "Gore", "Jump", "Sleep" }), new AssemblyMatchingRule("Domain") }, new string[] { "LoggingCallHandler", "CounterCallHandler" }); var interceptor = new InterfaceInterceptor(); var

Dagger 2 Inject Context in Kotlin Object

岁酱吖の 提交于 2020-01-16 07:49:08
问题 I am trying to inject Context using Dagger 2. AppComponent.kt: @Singleton @Component( modules = [ AppModule::class ] ) interface AppComponent { fun context(): Context } AppModule.kt: @Module class AppModule(private val application: Application) { @Provides @Singleton fun providesApplicationContext(): Context = application } MainApp.kt: class MainApp : Application() { lateinit var appComponent: AppComponent override fun onCreate() { super.onCreate() appComponent = initDagger() } private fun

When would you need SimpleInjector hybrid registration? (How can an object hosted in IIS be called without a HttpContext?)

我们两清 提交于 2020-01-16 02:05:43
问题 Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it seems I do not fully understand the technical requirements and have been doing something I don't actually need to do. With this code interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfWork { } interface IThreadUnitOfWork : IUnitOfWork { } class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { } container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>(); container

When would you need SimpleInjector hybrid registration? (How can an object hosted in IIS be called without a HttpContext?)

折月煮酒 提交于 2020-01-16 02:05:08
问题 Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it seems I do not fully understand the technical requirements and have been doing something I don't actually need to do. With this code interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfWork { } interface IThreadUnitOfWork : IUnitOfWork { } class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { } container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>(); container

Multiple language components/classes [OOP/Patterns/IoC/DI]

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 00:53:25
问题 I have several components for which there exists different versions, depending on the language used by the system (configurable, and can be changed at runtime). For example, I have an interface ("component") for Tokenizer , and two concrete implementations for english and chinese, like so: public interface Tokenizer { List<String> tokenize(String s); } public class EnglishTokenizer implements Tokenizer { List<String> tokenize(String s) { ... }; } public interface ChineseTokenizer implements

How To Scope Individual Libraries Using Auto Registration

一个人想着一个人 提交于 2020-01-16 00:45:00
问题 Is it possible to set/change the dependency lifetime scoping options (Transient, Single, PerWebReqest, etc...) for one, two or x number of specific assemblies if you're auto registering/discovering your dependencies? I have sample code below: public class RegistrationPackage : IPackage { public void RegisterServices(Container container) { var @namespace = "ConsoleLib"; var assemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(a => a.FullName.StartsWith(@namespace)) .Select(a => a)

How does Kephas integrate with ASP.NET Core?

为君一笑 提交于 2020-01-16 00:41:52
问题 So much I could understand, Kephas does not provide its own DI container, but it builds adapters on existing ones (Kephas has its own dependecy injection container. Why another framework, why not use an existing one?). Existing adapters are for System.Composition (MEF2) and, as I learned recently, for Autofac (starting with version 6.5.0, Cannot use constructors in open generic services with Kephas). However, ASP.NET comes with its own implementation of a DI container. In this regard, is it

Does it make sense to check for null values in injected arguments?

狂风中的少年 提交于 2020-01-15 21:17:32
问题 I am using Unity in my application. Does it make sense to check for null values in the constructor for the injected values? public class ExampleClass { public ExampleClass(IExampleArgument e) { if (e == null) //Do something } } Shouldn't the argument be resolved already and bound to a value? And in case a problem happens, it should occur during resolving, so I either have a value here or I don't? 回答1: Does it make sense to check for null values in the constructor for the injected values?

Does it make sense to check for null values in injected arguments?

走远了吗. 提交于 2020-01-15 21:17:17
问题 I am using Unity in my application. Does it make sense to check for null values in the constructor for the injected values? public class ExampleClass { public ExampleClass(IExampleArgument e) { if (e == null) //Do something } } Shouldn't the argument be resolved already and bound to a value? And in case a problem happens, it should occur during resolving, so I either have a value here or I don't? 回答1: Does it make sense to check for null values in the constructor for the injected values?

Resolve component in both tagged scope and untagged scope

假装没事ソ 提交于 2020-01-15 17:19:12
问题 I'm try to supply a different service to some tagged lifetime scopes in AutoFac, but can't seem to get the hang of it. I've tried using the custom lifetime from Instance per matching lifetime scope, with default? but that didn't work. I've written a test that illustrates what I'm trying to do: [TestMethod] public void NamedLifetimeTests() { var builder = new ContainerBuilder(); builder.Register(c => new ChildA()).As<Parent>().InstancePerLifetimeScope(); builder.Register(c => new ChildB()).As