dependency-injection

AngularJS Filter with TypeScript and injection

情到浓时终转凉″ 提交于 2019-12-19 07:08:04
问题 Can somebody provide me with an example of how I can create an Angular Filter in TypeScript that uses dependency injection. At the bottom is what I currently have, which is working fine, but what I want to do is in is the function I want to have access to $filter, so that I can change the line return date.ToString() into $filter'date'. That way I use the built in date filter to show a nice friendly short date. class FriendlyDateFilter { public static Factory() { return function (input):

Changing Guice bindings at runtime

我只是一个虾纸丫 提交于 2019-12-19 05:24:14
问题 I would like to be able to change the Guice injections at runtime to support multiple injections based on user input. This is what I would like to achieve: public interface IDao { public int someMethod(); } public class DaoEarth implements IDao { @Override public int someMethod(){ ... } } public class DaoMars implements IDao { @Override public int someMethod(){ ... } } public class MyClass { @Inject private IDao myDao; public int myMethod(String domain) { //If Domain == Earth, myDao should be

Is there any way to override a bean discovered by component scan?

笑着哭i 提交于 2019-12-19 05:13:27
问题 I have a java configuration class providing fooBean directly and barBean by component scan. @Configuration @ComponentScan(basePackages = { "com.blah" }) public class Config { @Bean public FooBean fooBean { return new FooBean(); } } and i want to reuse it in the test cases and i need to replace the beans with mocks: @Configuration @Import(Config.class) public class TestConfig { @Bean public FooBean fooBean { return new FooBeanMock(); } @Bean public BarBean barBean { return new BarBeanMock(); }

Dependency injection and Entity Framework

帅比萌擦擦* 提交于 2019-12-19 04:23:02
问题 I'm doing a wpf application using MVVM light with its Ioc SimpleIoc . I implemented the repository pattern like this : public interface ICrud<T> where T : class { IEnumerable<T> GetAll(); Task<IEnumerable<T>> AsyncGetAll(); void AddNew(params T[] items); void Delete(params T[] items); void Update(params T[] items); void SaveOrUpdate(params T[] items); } public class Crud<T> : ICrud<T> where T : class { public void AddNew(params T[] items) { using (var context = new DataEntities()) { foreach

Dependency injection and Entity Framework

╄→尐↘猪︶ㄣ 提交于 2019-12-19 04:22:00
问题 I'm doing a wpf application using MVVM light with its Ioc SimpleIoc . I implemented the repository pattern like this : public interface ICrud<T> where T : class { IEnumerable<T> GetAll(); Task<IEnumerable<T>> AsyncGetAll(); void AddNew(params T[] items); void Delete(params T[] items); void Update(params T[] items); void SaveOrUpdate(params T[] items); } public class Crud<T> : ICrud<T> where T : class { public void AddNew(params T[] items) { using (var context = new DataEntities()) { foreach

Dependency Injection inside of HttpSessionListener implementation

两盒软妹~` 提交于 2019-12-19 04:15:25
问题 Problem: This injected dependency will always return 0 from SimpleController Why does the context get lost for this bean when trying to do dependency injection into an HttpSessionListener implementation? What is principles behind this am I missing/confusing for this not to be working? How do I fix this? Project on Github webApp project Source Consider the following: SessionCounterListener public class SessionCounterListener implements HttpSessionListener { @Autowired private SessionService

How to call an Angular 4 method from a standalone plain JavaScript function?

陌路散爱 提交于 2019-12-19 04:12:19
问题 I'd like to be able to pass some data\propagate events from a plugin on the page to my Angular 4 app. More specifically, in my case data\events are generated inside a Silverlight plugin app that is next to the Angular app on the page. I have the following solution in my mind: Create a global JS function which gets called from Silverlight (since this seems to be the simplest way to get data out from Silverlight) when there is a need to talk to Angular side. The function, in turn, calls some

Can any of existing IoC containers create the lazy proxy classes dynamically?

夙愿已清 提交于 2019-12-19 04:07:14
问题 I study different DI patterns. And now I interested in the lazy life-time implementation. For example, I want to write a proxy class that hides the factory behind a service's interface. Can any of existing IoC containers (.NET) create this kind of proxy class dynamically at runtime? interface IService { void Foo(); void Bar(); } class ServiceFactoryProxy : IService { private readonly Func<IService> _factory; public ServiceFactoryProxy(Func<IService> factory) { if (factory == null) throw new

Passing in the type of the declaring class for NLog using Autofac

青春壹個敷衍的年華 提交于 2019-12-19 03:37:10
问题 Following on from this question I would like autofac to inject the type of the declaring object into the constructor of my NLog service, so that it can correctly log which type is logging entries. My NLogService class looks like this... public class NLogService : ILogService { private readonly Logger _logger; public NLogService(Type t) { var consumerType = t.DeclaringType.FullName; _logger = LogManager.GetLogger(consumerType); } However it fails on app startup because it obviously cannot work

Dynamic selection of interface implementation using IoC

时间秒杀一切 提交于 2019-12-19 03:13:24
问题 I have a situation where the implementation of an interface is determined at runtime. For example, I check a string and then determine which subclass to use, without IoC it looks like the following: if (fruitStr == "Apple") { new AppleImpl().SomeMethod(); } else { new BananaImpl().SomeMethod(); } Both classes AppleImpl and BananaImpl are implementation of the same interface, say IFruit . How can this be done using IoC/Dependency Injection, especially in Castle Windsor ? 回答1: This is the