dependency-injection

How do I pass a dependency to a Serilog Enricher?

你离开我真会死。 提交于 2019-12-23 08:49:58
问题 I'm using Serilog in my application for logging. When I'm configuring the logger, I have code like this: var log = new LoggerConfiguration() .Enrich.With<MySerilogEnricher>() .ReadAppSettings() .CreateLogger(); I want to inject some dependencies into my MySerilogEnricher class, but when I try, I get this compiler error: error CS0310: 'SerilogEnricher' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TEnricher' in the generic type or method

Create request scoped beans from a Java 8 Function

青春壹個敷衍的年華 提交于 2019-12-23 08:47:09
问题 Based on this answer I try to configure a request scope bean using java.util.Function interface. My Configuration looks like this: @Configuration public class RequestConfig { @Bean public Function<? extends BaseRequest, RequestWrapper<? extends BaseRequest, ? extends BaseResponse>> requestWrapperFactory() { return request -> requestWrapper(request); } @Bean @RequestScope public RequestWrapper<? extends BaseRequest, ? extends BaseResponse> requestWrapper( BaseRequest request) { RequestWrapper<

Spring Injection - access to the injected object within a constructor

ぃ、小莉子 提交于 2019-12-23 08:04:20
问题 I have a resource (Spring bean) which has some of its fields injected by Spring, for example: @Repository(value="appDao") public class AppDaoImpl implements AppDao { @PersistenceContext EntityManager entityManager; public Resource() { ... use entityManager ... // doesn't work } } I know that I can't access the injected entityManager in the constructor and should use a @PostConstruct annotation on a different method. But what are the reasons for this? 回答1: Because Spring can't access any

MVC3 + Ninject: What is the proper way to inject the User IPrincipal?

南楼画角 提交于 2019-12-23 07:55:40
问题 I have seen the following two example for injecting the User IPrincipal: Method 1: kernel.Bind<IPrincipal>() .ToMethod(context => context.Kernel.Get<RequestContext>().HttpContext.User) .InRequestScope(); Method 2: kernel.Bind<IPrincipal>() .ToMethod(context => HttpContext.Current.User) .InRequestScope(); Is there any difference in the two? Is one preferred? 回答1: The two methods are identical. Both are going to return the HttpContext obect for the current HTTP Request. 来源: https:/

Angular 2 - Inject a dependency into a decorator factory

余生长醉 提交于 2019-12-23 07:39:22
问题 Is there a way to inject a dependency into a decorator factory, using Angular's DI? Let's take the following code as a simplified example: @Component({ selector: 'hello-component', template: '<div>Hello World</div>' }) export class HelloComponent { @PersonName() name: string; ngAfterViewInit() { console.log(`Hello, ${this.name}`); } } Here, the intended behaviour of the PersonName decorator is for it to access a Person dependency, and use it to set the name property of the class. Is it

Entity Framework returning old data

天大地大妈咪最大 提交于 2019-12-23 07:16:14
问题 I have a problem with EF not returning the newest data in a 3 layered WPF application, and I suspect it has something to do with how I handle the lifetime of my context. This is the scenario: There are several repositories wrapped inside a UnitOfWork. There is also one service (MyService), which uses the UnitOfWork. This UnitOfWork must also be called from the UI directly, without passing through a service. In the ViewModel of my main window at some point I create a new window (using

Entity Framework returning old data

∥☆過路亽.° 提交于 2019-12-23 07:15:52
问题 I have a problem with EF not returning the newest data in a 3 layered WPF application, and I suspect it has something to do with how I handle the lifetime of my context. This is the scenario: There are several repositories wrapped inside a UnitOfWork. There is also one service (MyService), which uses the UnitOfWork. This UnitOfWork must also be called from the UI directly, without passing through a service. In the ViewModel of my main window at some point I create a new window (using

Simple Injector registration problem in SignalR

主宰稳场 提交于 2019-12-23 07:03:08
问题 I set DI in my Controller as shown below and tied to register IHubContext as it seen on Controller: public class DemoController : Controller { private IHubContext<DemoHub> context; public DemoController(IHubContext<DemoHub> context) { this.context = context; } } Global.asax: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); BundleConfig.RegisterBundles(BundleTable

Ninject bind all classes implementing the same interface

孤者浪人 提交于 2019-12-23 06:58:39
问题 I have an interface class: public interface IStartUpTask { bool IsEnabled { get; } void Configure(); } I have multimple classes implementing the same interface One of the classes looks like this: public class Log4NetStartUpTask : IStartUpTask { public bool IsEnabled { get { return true; } } public void Configure() { string log4netConfigFilePath = ConfigurationManager.AppSettings["log4netConfigFilePath"]; if (log4netConfigFilePath == null) throw new Exception("log4netConfigFilePath

Angular2: Cannot read property 'call' of undefined (when bootstrapping)

不羁岁月 提交于 2019-12-23 06:58:10
问题 Check the update on the bottom! I have a service that throws an error while the app is bootstrapping. Cannot read property 'call' of undefined . I'm using ng2 2.4.2 and angular-cli 1.0.0-beta.24. ERROR Uncaught TypeError: Cannot read property 'call' of undefined at webpack_require (bootstrap 81b10f8…:52) at Object.621 (environment.ts:8) at webpack_require (bootstrap 81b10f8…:52) at Object.450 (src async:7) at webpack_require (bootstrap 81b10f8…:52) at Object.1057 (util.service.ts:35) at