pyc-website

main website for pyc inc.

git clone https://9o.is/git/pyc-website.git

DependencyFactory.scala

(1348B)


      1 package inc.pyc
      2 package lib
      3 
      4 import java.util.Date
      5 
      6 import net.liftweb._
      7 import http._
      8 import util._
      9 import common._
     10 
     11 /**
     12  * A factory for generating new instances of Date.  You can create
     13  * factories for each kind of thing you want to vend in your application.
     14  * An example is a payment gateway.  You can change the default implementation,
     15  * or override the default implementation on a session, request or current call
     16  * stack basis.
     17  */
     18 object DependencyFactory extends Factory {
     19   implicit object time extends FactoryMaker(Helpers.now _)
     20 
     21   /**
     22    * objects in Scala are lazily created.  The init()
     23    * method creates a List of all the objects.  This
     24    * results in all the objects getting initialized and
     25    * registering their types with the dependency injector
     26    */
     27   private def init() {
     28     List(time)
     29   }
     30   init()
     31 }
     32 
     33 /*
     34 /**
     35  * Examples of changing the implementation
     36  */
     37 sealed abstract class Changer {
     38   def changeDefaultImplementation() {
     39     DependencyFactory.time.default.set(() => new Date())
     40   }
     41 
     42   def changeSessionImplementation() {
     43     DependencyFactory.time.session.set(() => new Date())
     44   }
     45 
     46   def changeRequestImplementation() {
     47     DependencyFactory.time.request.set(() => new Date())
     48   }
     49 
     50   def changeJustForCall(d: Date) {
     51     DependencyFactory.time.doWith(d) {
     52       // perform some calculations here
     53     }
     54   }
     55 }
     56 */