Use db.Context for ObjectFactory
@@ -18,25 +18,23 @@ package icobject
import "github.com/icon-project/goloop/common/db"
-type ImplFactory func(tag Tag) (Impl, error)
+const (
+ objectFactoryName = "objectFactory"
+)
-type databaseWithFactory struct {
- db.Database
- factory ImplFactory
-}
+type ImplFactory func(tag Tag) (Impl, error)
func AttachObjectFactory(database db.Database, factory ImplFactory) db.Database {
- if dwf, ok := database.(*databaseWithFactory); ok {
- return dwf
- }
- return &databaseWithFactory{
- database, factory,
- }
+ return db.WithFlags(database, db.Flags{
+ objectFactoryName: factory,
+ })
}
func FactoryOf(database db.Database) ImplFactory {
- if dbf, ok := database.(*databaseWithFactory); ok {
- return dbf.factory
- }
+ flag := db.GetFlag(database, objectFactoryName)
+ if factory, ok := flag.(ImplFactory); ok {
+ return factory
+ } else {
return nil
}
+}
