Difference between revisions of "Override Default Services Implementation for AC Gold"

From AbleCommerce Wiki
Jump to: navigation, search
(Introduction)
(How to override the default service implementations)
 
(11 intermediate revisions by 2 users not shown)
Line 9: Line 9:
 
It is not required to learn anything about Windsor or any other IOC container to override the default implementation of any service, however some information and help/tutorial links are provided at the end for completion.
 
It is not required to learn anything about Windsor or any other IOC container to override the default implementation of any service, however some information and help/tutorial links are provided at the end for completion.
  
== How to Override Default Services Implementation for AC Gold ==
+
== How to override the default service implementations ==
  
Follow these steps to override any default services implementation with your custom implementation:
+
Follow these steps to override a default service implementation with your custom implementation:
  
1. Implement the respective service interface, and compile the code to some assembly and copy the dll file at "~/App_Data/Bin/" folder under your website.
+
'''1.''' Implement the respective service interface, and compile the code to some assembly and copy the dll file at "~/Bin/" folder under your website.
  
2. Locate the "~/App_Data/windsor.config" file and open for editing using some text editor like Notepad.
+
'''2.''' Locate the "~/App_Data/windsor.config" file and open for editing using some text editor.
  
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:
+
'''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:
 
<pre><component id="MyCouponCalculator" service="CommerceBuilder.Services.ICouponCalculator, CommerceBuilder"
 
<pre><component id="MyCouponCalculator" service="CommerceBuilder.Services.ICouponCalculator, CommerceBuilder"
 
  type="MyCustomNamespace.MyCouponCalculator, MyCustomAssembly"/></pre>
 
  type="MyCustomNamespace.MyCouponCalculator, MyCustomAssembly"/></pre>
Line 23: Line 23:
 
The "service" attribute contains the assembly ("CommerceBuilder" in our case) and service interface information, while the "type" attribute contains information about your custom service implementing class and assembly.
 
The "service" attribute contains the assembly ("CommerceBuilder" in our case) and service interface information, while the "type" attribute contains information about your custom service implementing class and assembly.
  
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:
+
After changing/updating the "~/App_Data/windsor.config" file, restart the IIS, and AC Gold will start using your custom service implementation.
 +
 
 +
 
 +
'''Shortcut for websites deployed as web applications''' :
 +
 
 +
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:
 
<pre><component id="MyShipRateQuoteCalculator" service="CommerceBuilder.Services.IShipRateQuoteCalculator, CommerceBuilder"
 
<pre><component id="MyShipRateQuoteCalculator" service="CommerceBuilder.Services.IShipRateQuoteCalculator, CommerceBuilder"
 
  type="AbleCommerce.Code.MyShipRateQuoteCalculator, AbleCommerce"/></pre>
 
  type="AbleCommerce.Code.MyShipRateQuoteCalculator, AbleCommerce"/></pre>
  
After changing/updating the "~/App_Data/windsor.config" file, restart the IIS, and it will start using your custom service implementation.
+
== List of services that can be overridden ==
  
== List of Services Resolvable by Windsor IOC Container ==
 
  
 +
'''1. CommerceBuilder.Catalog.IUrlGenerator'''
  
1. CommerceBuilder.Catalog.IUrlGenerator
+
Interface to be implemented by catalog URL generators
  
Interface to be implemented by catalog URL Generator providers
 
  
 +
'''2. CommerceBuilder.Catalog.IUrlRewriter'''
  
2. CommerceBuilder.Catalog.IUrlRewriter
+
Interface that is to be implemented by URL rewrite providers
  
Interface that is to be implemented by URL Rewrite providers
 
  
 +
'''3. CommerceBuilder.Catalog.IUrlCache'''
  
3. CommerceBuilder.Catalog.IUrlCache
+
Interface to be implemented by URL caching service
  
Url Caching service interface
 
  
 +
'''4. CommerceBuilder.Eventing.IStoreEventsHandler'''
  
4. CommerceBuilder.Eventing.IStoreEventsHandler
+
Interface to be implemented by store events handler. This could be very useful for your own custom events handling.
  
Interface to be implemented by store events handler
 
  
 +
'''5. CommerceBuilder.Payments.IGiftCertKeyProvider'''
  
5. CommerceBuilder.Payments.IGiftCertKeyProvider
+
Interface that a gift certificate key provider must implement
  
Interface that a Gift Certificate Key Provider must implement
 
  
 +
'''6. CommerceBuilder.Services.ICouponCalculator'''
  
6. CommerceBuilder.Services.ICouponCalculator
+
Interface to be implemented by the coupon calculator service
  
CouponCalculator service interface
 
  
 +
'''7. CommerceBuilder.Services.IInventoryManager'''
  
7. CommerceBuilder.Services.IInventoryManager
+
Interface to be implemented by the inventory management service
  
Interface for inventory management services.
 
  
 +
'''8. CommerceBuilder.Services.IAffiliateCalculator'''
  
8. CommerceBuilder.Services.IAffiliateCalculator
+
Interface to be implemented by the affiliate commissions calculating service
  
Service Interface for calculating affiliate commissions.
 
  
 +
'''9. CommerceBuilder.Services.IBasketCalculator'''
  
9. CommerceBuilder.Services.IBasketCalculator
+
Interface to be implemented by the service used for various basket related calculations
  
Defines a service for performing basket calculations.
 
  
 
+
'''10. CommerceBuilder.Services.Checkout.IBasketService'''
10. CommerceBuilder.Services.Checkout.IBasketService
+
  
 
Service interface for pre-checkout logic and basket calculations
 
Service interface for pre-checkout logic and basket calculations
  
  
11. CommerceBuilder.Services.Checkout.ICheckoutService
+
'''11. CommerceBuilder.Services.Checkout.ICheckoutService'''
  
Service interface for checkout logic and calculations
+
Interface to be implemented by the checkout service
  
  
12. CommerceBuilder.Services.IDiscountCalculator
+
'''12. CommerceBuilder.Services.IDiscountCalculator'''
  
Service interface for discount calculator
+
Interface to be implemented by the discount calculator service
  
  
13. CommerceBuilder.Services.Membership.IUserLocator
+
'''13. CommerceBuilder.Services.Membership.IUserLocator'''
  
Defines the contract for a user locator.
+
Interface to be implemented by the user locator service
  
  
14. CommerceBuilder.Services.IOrderCalculator
+
'''14. CommerceBuilder.Services.IOrderCalculator'''
  
Defines a service for performing order calculations.
+
Interface to be implemented by the service for performing various order calculations
  
  
15. CommerceBuilder.Services.IOrderService
+
'''15. CommerceBuilder.Services.IOrderService'''
  
Processes business logic related to orders.
+
Interface to be implemented by the service for processes business logic related to orders
  
  
16. CommerceBuilder.Services.IPaymentMethodProvider
+
'''16. CommerceBuilder.Services.IPaymentMethodProvider'''
  
Defines a service for payment method providers.
+
Interface to be implemented by a service for payment method providers
  
  
17. CommerceBuilder.Services.IShipRateQuoteCalculator
+
'''17. CommerceBuilder.Services.IShipRateQuoteCalculator'''
  
Defines a service for calculation of ship rate quote
+
Interface to be implemented by a service for calculation of ship rate quotes
  
  
18. CommerceBuilder.Services.IVolumeDiscountProvider
+
'''18. CommerceBuilder.Services.IVolumeDiscountProvider'''
  
Defines a service for validating volume discounts.
+
Interface to be implemented by a service for validating volume discounts
  
  
19. CommerceBuilder.Services.IFullTextSearchService
+
'''19. CommerceBuilder.Services.IFullTextSearchService'''
  
 
FTS service interface
 
FTS service interface
  
  
20. CommerceBuilder.Services.IMaintenanceWorker
+
'''20. CommerceBuilder.Services.IMaintenanceWorker'''
  
Runs all maintenance routines for the current store context
+
Interface to be implemented by the service that runs all maintenance routines for the current store context
  
  
21. CommerceBuilder.Services.IPageTracker
+
'''21. CommerceBuilder.Services.IPageTracker'''
  
Page tracking service contract
+
Interface to be implemented by the page tracking service
  
  
22. CommerceBuilder.Services.ISQLFullTextSearchService
+
'''22. CommerceBuilder.Services.ISQLFullTextSearchService'''
  
 
SQL Full Text Search (FTS) service interface
 
SQL Full Text Search (FTS) service interface
  
  
23. CommerceBuilder.Services.IOrderStatusService
+
'''23. CommerceBuilder.Services.IOrderStatusService'''
  
Provides order status get/update services
+
Interface to be implemented by the service that provides order status get/update services
  
  
24. CommerceBuilder.Services.IStoreLocator
+
'''24. CommerceBuilder.Services.IStoreLocator'''
  
Store Locator service interface
+
Interface to be implemented by the store locator service
  
  
25. CommerceBuilder.Services.IStoreSettingsProvider
+
'''25. CommerceBuilder.Services.IStoreSettingsProvider'''
  
Store Settings Provider service interface
+
Interface to be implemented by the service that provides store settings for a given store
  
  
26. CommerceBuilder.Shipping.IPostalCodeValidator
+
'''26. CommerceBuilder.Shipping.IPostalCodeValidator'''
  
Postal code validator service
+
Interface to be implemented by the postal code validator service
  
  
27. CommerceBuilder.Seo.IRedirectService
+
'''27. CommerceBuilder.Seo.IRedirectService'''
  
Interface for SEO Redirect Service
+
Interface to be implemented by the SEO redirect service
  
  
28. CommerceBuilder.Utility.IAddressFormatter
+
'''28. CommerceBuilder.Utility.IAddressFormatter'''
  
Address formater service
+
Interface to be implemented by the address formatter service
 +
 
 +
== Sample Implementation ==
 +
A good example of how default services can be overridden is implementation of a custom event handler for your store. The following article explains how to implement a custom store event handler.
 +
[[How to hook and execute custom code against store events|Custom Store Event Handler Example]]
  
 
== Inversion of Control ==
 
== Inversion of Control ==
Line 195: Line 202:
  
 
http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx
 
http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx
 +
 +
[[Category:AbleCommerce Gold]]

Latest revision as of 10:57, 8 July 2022

Introduction

Different features in AbleCommerce GOLD are implemented via services, for example coupon calculator service, checkout service, shipping and tax quotes calculation service and etc. CommerceBuilder API makes these services available to be overridden by the custom implementations. Castle Windsor IOC Container is used to resolve the implementation of these services and it is fairly easy to override the default implementations of these services with a custom implementation.


Each service has a defined interface that the service provider class has to implement. For example the default implementation of ship rate calculation service is defined by the interface "CommerceBuilder.Services.IShipRateQuoteCalculator" and is implemented by the class "CommerceBuilder.Services.ShipRateQuoteCalculator". You can provide your own custom implementation by implementing the service interface and update the Windsor config file to make use of use your custom implementation.


It is not required to learn anything about Windsor or any other IOC container to override the default implementation of any service, however some information and help/tutorial links are provided at the end for completion.

How to override the default service implementations

Follow these steps to override a default service implementation with your custom implementation:

1. Implement the respective service interface, and compile the code to some assembly and copy the dll file at "~/Bin/" folder under your website.

2. Locate the "~/App_Data/windsor.config" file and open for editing using some text editor.

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"/>

The "service" attribute contains the assembly ("CommerceBuilder" in our case) and service interface information, while the "type" attribute contains information about your custom service implementing class and assembly.

After changing/updating the "~/App_Data/windsor.config" file, restart the IIS, and AC Gold will start using your custom service implementation.


Shortcut for websites deployed as web applications :

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"/>

List of services that can be overridden

1. CommerceBuilder.Catalog.IUrlGenerator

Interface to be implemented by catalog URL generators


2. CommerceBuilder.Catalog.IUrlRewriter

Interface that is to be implemented by URL rewrite providers


3. CommerceBuilder.Catalog.IUrlCache

Interface to be implemented by URL caching service


4. CommerceBuilder.Eventing.IStoreEventsHandler

Interface to be implemented by store events handler. This could be very useful for your own custom events handling.


5. CommerceBuilder.Payments.IGiftCertKeyProvider

Interface that a gift certificate key provider must implement


6. CommerceBuilder.Services.ICouponCalculator

Interface to be implemented by the coupon calculator service


7. CommerceBuilder.Services.IInventoryManager

Interface to be implemented by the inventory management service


8. CommerceBuilder.Services.IAffiliateCalculator

Interface to be implemented by the affiliate commissions calculating service


9. CommerceBuilder.Services.IBasketCalculator

Interface to be implemented by the service used for various basket related calculations


10. CommerceBuilder.Services.Checkout.IBasketService

Service interface for pre-checkout logic and basket calculations


11. CommerceBuilder.Services.Checkout.ICheckoutService

Interface to be implemented by the checkout service


12. CommerceBuilder.Services.IDiscountCalculator

Interface to be implemented by the discount calculator service


13. CommerceBuilder.Services.Membership.IUserLocator

Interface to be implemented by the user locator service


14. CommerceBuilder.Services.IOrderCalculator

Interface to be implemented by the service for performing various order calculations


15. CommerceBuilder.Services.IOrderService

Interface to be implemented by the service for processes business logic related to orders


16. CommerceBuilder.Services.IPaymentMethodProvider

Interface to be implemented by a service for payment method providers


17. CommerceBuilder.Services.IShipRateQuoteCalculator

Interface to be implemented by a service for calculation of ship rate quotes


18. CommerceBuilder.Services.IVolumeDiscountProvider

Interface to be implemented by a service for validating volume discounts


19. CommerceBuilder.Services.IFullTextSearchService

FTS service interface


20. CommerceBuilder.Services.IMaintenanceWorker

Interface to be implemented by the service that runs all maintenance routines for the current store context


21. CommerceBuilder.Services.IPageTracker

Interface to be implemented by the page tracking service


22. CommerceBuilder.Services.ISQLFullTextSearchService

SQL Full Text Search (FTS) service interface


23. CommerceBuilder.Services.IOrderStatusService

Interface to be implemented by the service that provides order status get/update services


24. CommerceBuilder.Services.IStoreLocator

Interface to be implemented by the store locator service


25. CommerceBuilder.Services.IStoreSettingsProvider

Interface to be implemented by the service that provides store settings for a given store


26. CommerceBuilder.Shipping.IPostalCodeValidator

Interface to be implemented by the postal code validator service


27. CommerceBuilder.Seo.IRedirectService

Interface to be implemented by the SEO redirect service


28. CommerceBuilder.Utility.IAddressFormatter

Interface to be implemented by the address formatter service

Sample Implementation

A good example of how default services can be overridden is implementation of a custom event handler for your store. The following article explains how to implement a custom store event handler. Custom Store Event Handler Example

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