dependency-injection

Getting multiple guice singletons of the same type

北城以北 提交于 2020-04-05 15:56:53
问题 can you get 2 singleton instances of the same underlying type? this is obviously trivial in spring as it is based on named instances to which you attach a scope but I can't see the equivalent in guice which is about binding types to implementation classes. Note that I don't want to have to bind to the instance as the instances in question are injected with other dependencies by guice. 回答1: It's easy in Guice too! Create two biding annotations, say @One and @Two and then bind(MySingleton.class

net core 2.0 xunit Controller with dependency injection using Mock is null

試著忘記壹切 提交于 2020-03-25 12:32:14
问题 I am doing an Net Core 2.0 Rest Api application. I am using dependency injection with Interface IContactBiz and class ContactBiz . IContactBiz is defined like this public interface IContactBiz { ReturnModel Add(List<ContactEntity> lstContactEntity, ContactEntity contact); } My ContactBiz class public class ContactBiz: IContactBiz { public ReturnModel Add(List<ContactEntity> lstContactEntity, ContactEntity contact) { contact.ID = Guid.NewGuid().ToString(); lstContactEntity.Add(contact); return

No service for type X has been registered, but service registration looks ok?

北慕城南 提交于 2020-03-24 00:17:47
问题 I have some very simple code in Startup.cs in a ASP.NET Core 2.0 web project: public async void ConfigureServices(IServiceCollection services) { services.AddMvc(); await CreateContainer(); services.AddSingleton<Infrastructure.Logging.Contracts.ILogger, Infrastructure.Logging.Standard.Logger>(); } private async Task CreateContainer() { string connectionString = Configuration["TestConnectionString"]; var storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobClient =

No service for type X has been registered, but service registration looks ok?

流过昼夜 提交于 2020-03-24 00:17:10
问题 I have some very simple code in Startup.cs in a ASP.NET Core 2.0 web project: public async void ConfigureServices(IServiceCollection services) { services.AddMvc(); await CreateContainer(); services.AddSingleton<Infrastructure.Logging.Contracts.ILogger, Infrastructure.Logging.Standard.Logger>(); } private async Task CreateContainer() { string connectionString = Configuration["TestConnectionString"]; var storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobClient =

Dagger: What if I *WANT* a new instance every time?

a 夏天 提交于 2020-03-22 05:50:52
问题 Interesting how difficult this answer is to find. I've been using Dagger - Android for a while now and have my entire dependency graph set up. I'm using scopes, qualifiers, all that good stuff. I'm not a Dagger newbie anymore, but suffice to say I've been using it in a pretty standard way in my Android setup and everything has been going great. For the first time, I'm realizing that I'd like to request new instances of a certain class in my graph myself, manually, and I want it to be a new

Dagger: What if I *WANT* a new instance every time?

六眼飞鱼酱① 提交于 2020-03-22 05:50:12
问题 Interesting how difficult this answer is to find. I've been using Dagger - Android for a while now and have my entire dependency graph set up. I'm using scopes, qualifiers, all that good stuff. I'm not a Dagger newbie anymore, but suffice to say I've been using it in a pretty standard way in my Android setup and everything has been going great. For the first time, I'm realizing that I'd like to request new instances of a certain class in my graph myself, manually, and I want it to be a new

Laravel: dependency injection in commands

空扰寡人 提交于 2020-03-21 16:01:33
问题 Is dependency injection of a custom class in a command possible? I'm trying this: <?php namespace vendor\package\Commands; use Illuminate\Console\Command; use vendor\package\Models\Log; use vendor\package\Updates\UpdateStatistics; class UpdatePublishmentStats extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'vendorname:updatePublishmentStats'; /** * The console command description. * * @var string */ protected $description =

@Injectable() decorator and providers array

三世轮回 提交于 2020-03-21 06:50:11
问题 Does a service that is provided in "root" within the @Injectable() decorator still have to be in the providers array of the module? The Angular documentation doesn't really give me an answer or I don't quite understand it. Inside my core folder I have a authentication service which is provided in root. I wan't to import my core module inside the app module in order to use all the services and components provided. Do I have to additionally set up the service in the providers array of the

Is there a Autofac integration library for WinForm

时光怂恿深爱的人放手 提交于 2020-03-20 06:00:36
问题 I am working on a Win form application with Autofac Here we resolve the dependencies as following: As seen in doc using (var scope = DIConfig.container.BeginLifetimeScope()) { var us = scope.Resolve<IUsersService>(); usersGrid.DataSource = us.GetUsers(); } However in Web MVC project we could resolve all dependencies Eg as in DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); So that there is no need to resolve the scope each time as in and use the simple code usersGrid

Is there a Autofac integration library for WinForm

落爺英雄遲暮 提交于 2020-03-20 06:00:06
问题 I am working on a Win form application with Autofac Here we resolve the dependencies as following: As seen in doc using (var scope = DIConfig.container.BeginLifetimeScope()) { var us = scope.Resolve<IUsersService>(); usersGrid.DataSource = us.GetUsers(); } However in Web MVC project we could resolve all dependencies Eg as in DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); So that there is no need to resolve the scope each time as in and use the simple code usersGrid