Difference between revisions of "Override Default Services Implementation for AC Gold"
(New page: == Inversion of Control == Inversion of Control is a principle used by frameworks as a way to allow developers to extend the framework or create applications using it. The basic idea is t...) |
|||
Line 49: | Line 49: | ||
CommerceBuilder.Catalog.IUrlRewriter | CommerceBuilder.Catalog.IUrlRewriter | ||
− | |||
− | |||
CommerceBuilder.Eventing.IStoreEventsHandler | CommerceBuilder.Eventing.IStoreEventsHandler |
Revision as of 15:52, 12 August 2013
Contents
Inversion of Control
Inversion of Control is a principle used by frameworks as a way to allow developers to extend the framework or create applications using it. The basic idea is that the framework is aware of the programmer's objects and makes invocations on them.
This is the opposite of using an API, where the developer's code makes the invocations to the API code. Hence, frameworks invert the control: it is not the developer code that is in charge, instead the framework makes the calls based on some stimulus.
You have probably been in situations where you have developed under the light of this principle, even though you were not aware of it.
Inversion of Control Container
An Inversion of Control Container uses the principle stated above to (in a nutshell) manage classes. That is, their creation, destruction, lifetime, configuration, and dependencies. This way classes do not need to obtain and configure the classes they depend on. This dramatically reduces coupling in a system and, as a consequence, simplifies reuse and testability.
There is some confusion created by people that think that 'Inversion of Control' is a synonym for 'Inversion of Control Container'. As stated, Inversion of control is a broader principle.
Often people think that it is all about "injection", and broadcast that this is the primary purpose of IoC containers. In fact, "injection" is a consequence, a means to decouple, not the primary purpose. http://docs.castleproject.org/Windsor.Inversion-of-Control.ashx
Castle Windsor IOC Container
For information about Castle Windsor IOC Container, help and tutorials check the official documentation: http://docs.castleproject.org/Windsor.MainPage.ashx
Asp.Net Tutorial
http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx
Castle Windsor IOC Container for AbleCommerce
AbleCommerce CommerceBuilder API implements many services for different features, for example Coupon Calculator service, Checkout service, Shipping and Tax quotes calculation services. And it uses Castle Windsor to resolve the implementation of these services. This way its fairly easy to override the default implementation of these services with a custom implementation.
Each service have an interface, and the implementation follows that interface. For example the default implementation "CommerceBuilder.Services.ShipRateQuoteCalculator" for shipping rate calculation service implements the interface "CommerceBuilder.Services.IShipRateQuoteCalculator". So, you can provide your own custom implementation by implementation the respective service interface and update the Windsor config file to use your custom implementation.
Follow these steps to override any default services implementation with your custom implementation:
1. Implement the respective service interface, and compile the code to some assembly.
2. Locate the "~/App_Data/windsor.config" file and open for editing using some text editor like Notepad.
3. Define your custom service implementations in "~/App_Data/windsor.config" file. For example if you have a custom coupon calculator implementation, you can define it there like this: <component id="MyCouponCalculator" service="CommerceBuilder.Services.ICouponCalculator, CommerceBuilder" type="MyCustomNamespace.MyCouponCalculator, MyCustomAssembly"/>
4. For store websites configured as web applications, you can implement your custom services under "~/Code/" folder instead creating a separate assembly project for it. In this case you can use "AbleCommerce.Code" namespace. For example: <component id="MyShipRateQuoteCalculator" service="CommerceBuilder.Services.IShipRateQuoteCalculator, CommerceBuilder" type="AbleCommerce.Code.MyShipRateQuoteCalculator, AbleCommerce"/>
After changing/updating the "~/App_Data/windsor.config" file, restart the IIS, and it will start using your custom service implementation.
List of Services Resolvable by Windsor IOC Container
CommerceBuilder.Catalog.IUrlGenerator
CommerceBuilder.Catalog.IUrlRewriter
CommerceBuilder.Eventing.IStoreEventsHandler
CommerceBuilder.Services.ICouponCalculator
CommerceBuilder.Services.IInventoryManager
CommerceBuilder.Seo.IRedirectService
CommerceBuilder.Services.IAffiliateCalculator
CommerceBuilder.Services.IBasketCalculator
CommerceBuilder.Services.Checkout.IBasketService
CommerceBuilder.Services.Checkout.ICheckoutService
CommerceBuilder.Services.IDiscountCalculator
CommerceBuilder.Services.Membership.IUserLocator
CommerceBuilder.Services.IOrderCalculator
CommerceBuilder.Services.IOrderService
CommerceBuilder.Services.IPaymentMethodProvider
CommerceBuilder.Services.IShipRateQuoteCalculator
CommerceBuilder.Services.IVolumeDiscountProvider
CommerceBuilder.Services.IFullTextSearchService
CommerceBuilder.Services.IMaintenanceWorker
CommerceBuilder.Services.IPageTracker
CommerceBuilder.Services.ISQLFullTextSearchService
CommerceBuilder.Payments.IGiftCertKeyProvider
CommerceBuilder.Catalog.IUrlCache
CommerceBuilder.Services.IOrderStatusService
CommerceBuilder.Services.IStoreLocator
CommerceBuilder.Services.IStoreSettingsProvider
CommerceBuilder.Shipping.IPostalCodeValidator
CommerceBuilder.Utility.IAddressFormatter