Sha256: d11dfef61242d06121083d4aebf47727d382c7008433d2ef74302b03b8c2b001

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

module Koine
  module Di
    class ServiceFactory
      def attach_to(dependency_manager)
        if shared?
          dependency_manager.share(dependency_key) do |di|
            create_service(di)
          end

          return
        end

        dependency_manager.set(dependency_key) do |di|
          create_service(di)
        end
      end

      def create_service(_dependency_manager)
        raise 'create_service must be implemented'
      end

      def dependency_key
        raise 'dependency_key must be implemented'
      end

      def shared?
        false
      end

      class << self
        private

        def share(boolean)
          instance_eval do
            define_method :shared? do
              boolean
            end
          end
        end

        def key(dependency_key)
          instance_eval do
            define_method :dependency_key do
              dependency_key
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
koine-di-1.0.0 lib/koine/di/service_factory.rb