inversion-of-control

Autofac assembly scanning - .NET Core

跟風遠走 提交于 2020-06-28 09:23:13
问题 I've been trying to get assembly scanning working in my .NET core 2.0 project. The exception I am getting Autofac.Core.Registration.ComponentNotRegisteredException HResult=0x80131500 Message=The requested service 'Microsoft.AspNetCore.Hosting.Internal.WebHostOptions' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

Name of Design Pattern: get class from class level

谁说胖子不能爱 提交于 2020-05-12 20:32:09
问题 Especially in unittests we use this "design pattern" I call "get class from class level" framworktest.py: class FrameWorkHttpClient(object): .... class FrameWorkTestCase(unittest.TestCase): # Subclass can control the class which gets used in get_response() HttpClient=FrameWorkHttpClient def get_response(self, url): client=self.HttpClient() return client.get(url) mytest.py: class MyHttpClient(FrameWorkHttpClient): .... class MyTestCase(FrameWorkTestCase): HttpClient=MyHttpClient def test

Name of Design Pattern: get class from class level

 ̄綄美尐妖づ 提交于 2020-05-12 20:31:29
问题 Especially in unittests we use this "design pattern" I call "get class from class level" framworktest.py: class FrameWorkHttpClient(object): .... class FrameWorkTestCase(unittest.TestCase): # Subclass can control the class which gets used in get_response() HttpClient=FrameWorkHttpClient def get_response(self, url): client=self.HttpClient() return client.get(url) mytest.py: class MyHttpClient(FrameWorkHttpClient): .... class MyTestCase(FrameWorkTestCase): HttpClient=MyHttpClient def test

Using Hibernate 4's Integrator pattern and Spring's dependency injection

戏子无情 提交于 2020-03-13 04:33:33
问题 I'm used to using Spring to do my dependency injection like so: <context:component-scan base-package="org.emmerich.myapp" /> and then annotating my dependent classes with Autowired like so: public class DependentClass { @Autowired private Dependency dependency; } However, with the changes in Hibernate 4.0, we're now advised to use the new Integrator interface for service discovery. This includes adding event listeners for triggers such as postUpdate , postDelete etc. Unfortunately, this doesn

Using Hibernate 4's Integrator pattern and Spring's dependency injection

别来无恙 提交于 2020-03-13 04:32:57
问题 I'm used to using Spring to do my dependency injection like so: <context:component-scan base-package="org.emmerich.myapp" /> and then annotating my dependent classes with Autowired like so: public class DependentClass { @Autowired private Dependency dependency; } However, with the changes in Hibernate 4.0, we're now advised to use the new Integrator interface for service discovery. This includes adding event listeners for triggers such as postUpdate , postDelete etc. Unfortunately, this doesn

How does the ViewModel constructor get the required interfaces?

谁都会走 提交于 2020-03-02 17:12:08
问题 My question based on InventorySampleApp by Microsoft. The ServiceLocator contains method Configure() that register Services and ViewModels. With method GetService<T>() we can get it. For example, ProductView.cs : ViewModel = ServiceLocator.Current.GetService<ProductDetailsViewModel>(); Each *ViewModel contains constructor with interface, for example: public ProductDetailsViewModel(IProductService productService, IFilePickerService filePickerService, ICommonServices commonServices) I can't

Differences and similarities between: ViewModelLocator, ServiceLocator, Dependency Injection

好久不见. 提交于 2020-02-25 02:13:01
问题 I'm confused about the patterns: ViewModelLocator , ServiceLocator , Dependency Injection . The latest conclusion are as follows: ViewModelLocator . The place to connect View and ViewModel . public ViewModelLocator() { SimpleIoc.Default.Register<MainViewModel>(); SimpleIoc.Default.Register<SettingViewModel>(); } public MainViewModel MainViewModel => SimpleIoc.Default.GetInstance<MainViewModel>(); public SettingViewModel SettingViewModel => SimpleIoc.Default.GetInstance<SettingViewModel>(); //

Dependency injection, composition root, and entry points

坚强是说给别人听的谎言 提交于 2020-02-04 03:50:28
问题 I've spent a lot of time reading these articles (along with many others): Mark Seemann - Pure DI Mark Seemann - When to use a DI Container Mark Seemann - Compose object graphs with confidence Mark Seemann - Don't call the container; it'll call you Mark Seemann - Understanding the Composition Root and I'm still trying to wrap my head around DI and the concept of "wiring up the dependencies" and the "auto wiring" functionality of an IoC container. I think I understand the theory of Dependency

Registering a type with multiple constructors and string dependency in Simple Injector

断了今生、忘了曾经 提交于 2020-02-01 00:37:36
问题 I'm trying to figure out how to use Simple Injector, I've used it around the project with no problems registering simple services and their components. However, I wanted to use dependency injector when having a component with more than two constructors that implements an interface. public DAL: IDAL { private Logger logger; string _dbInstance; public DAL() { logger = new Logger(); } public DAL(string databaseInstance) { logger = new Logger(); _dbInstance = databaseInstance; } } Here is how I'm

Guice: How to change injection on runtime based on a (dynamic web property)

心不动则不痛 提交于 2020-01-30 19:36:07
问题 The following is an approximation of the problem I'm facing. Think we have a password validator with some rules. public interface RuleChecker{ //Checks for a password strenght, returns 10 //for strong or 0 for soft password. int check(String pass); } And then we have several implementations, our service will only accept the password if it is over 8 score. public class NoCheck implements RuleChecker { public int check(String pass){return 10;} } public class LengthCheck implements RuleChecker{