What’s the Python version for “Code against an interface, not an object”?

“Code against an interface, not an object” doesn’t make literal sense in Python because the language doesn’t have an interface feature. The rough Python equivalent is “use duck typing.” If you want to see if an object is a duck, in other words, you should check to see whether it has a quack() method, or … Read more

Generic Type in constructor

You can’t make constructors generic, but you can use a generic static method instead: public static Constructor CreateInstance<T>(int blah, IGenericType<T> instance) and then do whatever you need to after the constructor, if required. Another alternative in some cases might be to introduce a non-generic interface which the generic interface extends. EDIT: As per the comments… … Read more

MEF (Managed Extensibility Framework) vs IoC/DI

The principle purpose of MEF is extensibility; to serve as a ‘plug-in’ framework for when the author of the application and the author of the plug-in (extension) are different and have no particular knowledge of each other beyond a published interface (contract) library. Another problem space MEF addresses that’s different from the usual IoC suspects, … Read more

how to use MVVMLight SimpleIoc? [closed]

SimpleIoc crib sheet: You register all your interfaces and objects in the ViewModelLocator class ViewModelLocator { static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); if (ViewModelBase.IsInDesignModeStatic) { SimpleIoc.Default.Register<IDataService, Design.DesignDataService>(); } else { SimpleIoc.Default.Register<IDataService, DataService>(); } SimpleIoc.Default.Register<MainViewModel>(); SimpleIoc.Default.Register<SecondViewModel>(); } public MainViewModel Main { get { return ServiceLocator.Current.GetInstance<MainViewModel>(); } } } Every object is a singleton by default. To … Read more

Understanding IoC Containers and Dependency Injection

Put simply (because it’s not a problem limited to OOP world only), a dependency is a situation where component A needs (depends on) component B to do the stuff it’s supposed to do. The word is also used to describe the depended-on component in this scenario. To put this in OOP/PHP terms, consider the following … Read more

MEF vs. any IoC

When boiled down, the main difference is that IoC containers are generally most useful with static dependencies (known at compile-time), and MEF is generally most useful with dynamic dependencies (known only at run-time). As such, they are both composition engines, but the emphasis is very different for each pattern. Design decisions thus vary wildly, as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)