dependency-injection

How to access not-injected services directly on Symfony 4+?

最后都变了- 提交于 2019-12-31 07:41:51
问题 I'm trying to update Symfony 2.8 to Symfony 4 and I am having serious problems with the Services Injection. I'm looking the new way to use Services inside Controllers, with auto-wiring: use App\Service\AuxiliarService; class DefaultController extends AbstractController { public function index(AuxiliarService $service) { $var = $service->MyFunction(); .... This way works fine, but I dislike the explicit way to refer MyService as a parameter of the function. This way I don't even need to

How to access not-injected services directly on Symfony 4+?

a 夏天 提交于 2019-12-31 07:41:33
问题 I'm trying to update Symfony 2.8 to Symfony 4 and I am having serious problems with the Services Injection. I'm looking the new way to use Services inside Controllers, with auto-wiring: use App\Service\AuxiliarService; class DefaultController extends AbstractController { public function index(AuxiliarService $service) { $var = $service->MyFunction(); .... This way works fine, but I dislike the explicit way to refer MyService as a parameter of the function. This way I don't even need to

What is the actual difference betwen a service locatior and a dependency injection?

家住魔仙堡 提交于 2019-12-31 06:20:08
问题 I was going through the previous discussion in which there was a detailed discussion on the difference between a service locator and a dependency injector, but still I am not able to get that. Can I get a general response without any code? 回答1: This code sample applies the Dependency Injection principle: public class UserService : IUserService { private IUserRepository repository; // Constructor taking dependencies public UserService(IUserRepository repository) { this.repository = repository;

Repository & Unit of Work Pattern for Entity Framework using Dependency Injection

寵の児 提交于 2019-12-31 04:14:10
问题 I tried the T4-Template from http://efrepository.codeplex.com, but I'm struggling with the DI (uses StructureMap) Example code. It's just not enough for a DI beginner like me. It doesn't even compile. I already have done a few sample projects with its Non-DI Template. And it worked out great. I love, that it generates all necessary repositories and that I can easily customize and extend them. But I can't get the DI Examples working. Are there any similar projects (with better docs)? 回答1: I

Angular 2 inject service into extended class(BaseRequestOptions)

99封情书 提交于 2019-12-31 03:48:07
问题 I have the following code that extends the BaseRequestOptions class: import { Injectable } from '@angular/core'; @Injectable() export class AppRequestOptions extends BaseRequestOptions { constructor(private serviceA:ServiceA) { super(); } merge(options?: RequestOptionsArgs): RequestOptions { console.log(this.serviceA); //this.serviceA.myCustomMethod(); return super.merge(options); } } When I reference this.serviceA the value is undefined . When I inject the same service into other services

How to inject ModelState as parameter with Ninject?

余生颓废 提交于 2019-12-31 03:26:10
问题 Im very new to Ninject. I want to find a way to pass Modelstate of a controller further to service layer. what i have right now: private readonly IAccountService service; public AccountController(ILanguageService ls, ISessionHelper sh) { this.service = new AccountService(new ModelStateWrapper(this.ModelState)); this.languageService = ls; this.sessionHelper = sh; } public AccountService(IValidationDictionary validationDictionary) { this.validationDictionary = validationDictionary; } want i

C# automatic creation of repositories by entity type

落爺英雄遲暮 提交于 2019-12-31 02:44:08
问题 I found an example of Generic Repository which is based on Entity Framework and trying to understand how to automatically resolve repositories by the same interface and entity type. The link above leads to the repo where you can see the following approach: public class HomeController : Controller { private readonly ICategoryRepository _repository; public HomeController(ICategoryRepository repository) { _repository = repository; } in this case we have to create a separate CategoryRepository -

Unable to register Api Controller using Simple Injector?

﹥>﹥吖頭↗ 提交于 2019-12-31 02:29:06
问题 I have a WebApi that uses Simple Injector that was working perfectly fine, but i had to implement OAuth in to the project. Now i have done that and my ApiControllers give me an error like Simple Injector has now been setup correctly I have my Start.cs file public class Startup { public void Configuration(IAppBuilder app) { // Web API configuration and services HttpConfiguration config = new HttpConfiguration(); Container container = SimpleInjectorConfig.Initialize(app); ConfigureAuth(app,

Simple Injector Diagnostic Warning Disposable Transient

女生的网名这么多〃 提交于 2019-12-30 18:44:08
问题 I am trying to configure simple injector to work, but I can't seem to get pass this. I followed the instructions on how to fix this in this link but it didn't work. Here is the error message: NotificationEntities is registered as transient, but implements IDisposable. Here is the code to the SimpleInjectorInitializer.cs public static void Initialize() { var container = new Container(); container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); InitializeContainer(container);

Castle Windsor IoC Property Injection simple how-to

自古美人都是妖i 提交于 2019-12-30 18:38:07
问题 OK I think there is maybe too much information about Castle Windsor because looking for these keywords gives me examples of everything, and frankly I don't understand enough about how it works to properly troubleshoot this. I have tried quite a few permutations with little luck at this point. I have an IUnitOfWorkFactory that I want to instantiate as a singleton. So, I install Castle Windsor, write a bit of code like so: iocContainer = new WindsorContainer() .Install(FromAssembly.This()); var