dependency-injection

ASP.NET Core MVC FromService binding in Controller returns empty collection

落爺英雄遲暮 提交于 2019-12-24 08:22:19
问题 Been trying to get a grip of ASP.NET Core MVC but got stuck with dependency injection returning empty collection in my controller action, despite of registering the service as Singleton in ConfigureService method. Tried two different ways to register but only one of them actually works. Said method is as following: public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); /***THIS DOES NOT WORK***/ services.AddSingleton<IRepository<Employee>,

Service sensio_distribution.webconfigurator no found

送分小仙女□ 提交于 2019-12-24 08:14:43
问题 I work on a Symfony2.4 project and I decided to go into production environment but when emptying the cache production I got this error : [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException] You have requested a non-existent service "sensio_distribution.webconfigurator". I don't know when this service is used but I searched the file "webconfigurator.xml" and I have found the service called "sensio_distribution.webconfigurator"... The file path is the following : vendor

Resolve instances by key and auto-registration with SimpleInjector

微笑、不失礼 提交于 2019-12-24 07:48:28
问题 I'm trying to resolve instances by key with SimpleInjector. In my case, the keys are strings which are coming from a configuration file, and I need the factory to return the correct type based on the string. I used a similar solution like the one described in the link above, but changed it slightly, so the instances can provide their own keys. (there will be many classes that implement IFoo , so I'd like to auto-register them with their keys) Here is the complete working example (.NET Core

Resolve instances by key and auto-registration with SimpleInjector

牧云@^-^@ 提交于 2019-12-24 07:48:25
问题 I'm trying to resolve instances by key with SimpleInjector. In my case, the keys are strings which are coming from a configuration file, and I need the factory to return the correct type based on the string. I used a similar solution like the one described in the link above, but changed it slightly, so the instances can provide their own keys. (there will be many classes that implement IFoo , so I'd like to auto-register them with their keys) Here is the complete working example (.NET Core

Dependency injection and initialization of the object

爷,独闯天下 提交于 2019-12-24 07:30:48
问题 I am quite a newbie to decent OOP and DI, thus was wondering, if the following example and its pattern of initialization of my bootstrap class, that includes dependent objects, is really alright to use, e.g.: new Session( new Config, new Database ( new Config ), new Page ( new Config ), new Statistics ( new Database ( new Config ) ), new Notification, new Filter ); I believe, those which familiar with DI could say something about the piece of code above in bootstrap object? It looks a bit

With unity and generics, are instances of closing types injected during the spinning up of the container and if so why?

百般思念 提交于 2019-12-24 07:13:40
问题 It appears this is the case. If I am marking a generic as a closed type, I am stating my intention to use a Type and not an Instance of a Type. I am getting an error as Unity is trying to resolve the closing type in the ExternalLinkingRepository class below. The error states that Unity can not reconcile the constructor as there is more than 1 with the same number of parameters (2). I have looked at constructor injectors (and indeed need one for the connection string, but this is not the issue

How to register custom build Autofac.Module in Orchard?

北城余情 提交于 2019-12-24 07:04:02
问题 I have a piece of code that encapsulates functionality that isn't specific to Orchard. However i need to make it available in Orchard via dependency injection. So, I built up an Autofac Module that registers all components (types), but I can't find a way to inform Orchard's Autofac Container about it. From what i red, there are two ways to add a module to a container: By supplying the module at to the ContainerBuilder (usually at start-up), Or by updating the already built Container at

Unity 1.2 Dependency injection of internal types

孤街浪徒 提交于 2019-12-24 07:02:12
问题 I have a facade in a library that exposes some complex functionality through a simple interface. My question is how do I do dependency injection for the internal types used in the facade. Let's say my C# library code looks like - public class XYZfacade:IFacade { [Dependency] internal IType1 type1 { get; set; } [Dependency] internal IType2 type2 { get; set; } public string SomeFunction() { return type1.someString(); } } internal class TypeA { .... } internal class TypeB { .... } And my website

How can I a get singleton from Guice that's configured with runtime parameters?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 06:49:43
问题 My overall goal is to load properties from a properties file and then inject those properties into my objects. I would also like to use those properties to instantiate certain singleton classes using Guice. My singleton class looks like this: public class MainStore(){ private String hostname; @Inject public void setHostname(@Named("hostname") String hostname){ this.hostname = hostname; } public MainStore(){ System.out.println(hostname); } } I'm trying to instantiate a singleton using this

Resolving dependencies in XAML using Autofac

北战南征 提交于 2019-12-24 06:47:45
问题 I have a class MyResource in my application that looks like this: public class MyResource : IMyResource { // ... whatever ... } And when I initialize my application in App.xaml.cs I have something like that using Autofac: builder.Register<IMyResource>(container => new MyResource()); Now I need to add a StaticResource in a Window of my WPF application, something like this: <Window.Resources> <local:MyResource x:Key="MyResource" /> </Window.Resources> But of course, the whole idea is not to