Skip to content
Browse files

Sprinkled some sugar now

  • Loading branch information...
1 parent 9fa1c46 commit 3a2c9c84905ce8bf922da32e37dd2f94fdb0ef20 @casualjim casualjim committed Mar 12, 2009
Showing with 23 additions and 53 deletions.
  1. +0 −1 Ninject.sln
  2. +23 −52 src/Ninject.Dynamic/initializer.rb
View
1 Ninject.sln
@@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
build-release.cmd = build-release.cmd
build.cmd = build.cmd
Ninject.build = Ninject.build
- README = README
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninject.Web.Mvc", "src\Ninject.Web.Mvc\Ninject.Web.Mvc.csproj", "{5C02730F-60D7-454E-88C7-B0C257B01C77}"
View
75 src/Ninject.Dynamic/initializer.rb
@@ -134,7 +134,7 @@ def to_dotnet_action
System::Action.of(IContext).new { |context| b.call(context.instance) }
end
- def to_provider_condition
+ def to_when_condition
b=self
System::Func.of(IRequest, System::Boolean).new { |request| b.call(request) }
end
@@ -152,10 +152,12 @@ def to_creation_callback
class Hash
def has_name?
- def has_name?
- self[:name].is_a?(String) || self[:name].is_a?(System::String) || self[:name].is_a?(Symbol) ||
- self[:name.to_s].is_a?(String) || self[:name.to_s].is_a?(System::String) || self[:name.to_s].is_a?(Symbol)
- end
+ self[:name].is_a?(String) || self[:name].is_a?(System::String) || self[:name].is_a?(Symbol) ||
+ self[:name.to_s].is_a?(String) || self[:name.to_s].is_a?(System::String) || self[:name.to_s].is_a?(Symbol)
+ end
+
+ def to_when_condition
+ value.send("to_#{self}_condition".to_sym)
end
end
@@ -246,11 +248,9 @@ def add_on_deactivation
binding.deactivation_actions.add handler.to_dotnet_action unless handler.nil? && !handler.respond_to? :each
end
- def add_when_constraints
- wh = config[:when]
- wh.each do |key, value|
- binding.condition = value.send("to_#{key}_condition".to_sym)
- end unless wh.nil?
+ def add_when_constraint
+ wh = config[:when]
+ binding.condition = wh.to_when_condition unless wh.nil?
end
def build
@@ -263,7 +263,7 @@ def build
add_property_values
add_on_activation
add_on_deactivation
- add_when_constraints
+ add_when_constraint
set_target
end
end
@@ -284,11 +284,22 @@ def initialize
@bindings = []
end
- def bind(service_type, config={})
+ def bind(service_type, config={}, &b)
config[:service] ||= service_type
+ @config = config
+ instance_eval &b unless b.nil?
@bindings << RubyBindingBuilder.new(config).build
end
+ def method_missing(receiver, message, args)
+ @@posibilities ||= [:meta, :name, :with, :on_activation, :on_deactivation, :activated, :deactivated, :when]
+ if @@posibilities.include?(message.to_sym)
+ @config[message.to_sym] = args
+ else
+ super #preserve normal behavior
+ end
+ end
+
def clear_bindings
@bindings=[]
end
@@ -301,43 +312,3 @@ def to_configure_ninject(&b)
b.call(initializer)
initializer.bindings
end
-
-
-# Step 1: create a builder
-#to_configure_ninject do |ninject|
-# ninject.bind IServiceA,
-# :to => ServiceA,
-# :as => :singleton,
-# :meta => { :type => "superservice" },
-# :name => "aaaaa",
-# :parameter => [{ :name => "my_param", :value => lambda { |context| "param_value" } }],
-# :constructor_arguments => [{:name => :const_arg, :value => 56 }],
-# :property_values => [{:name => :property_name, :value => 94 }],
-# :on_activation => lambda { |obj| obj.do_some_work },
-# :on_deativated => lambda { |obj| obj.do_some_cleanup },
-# :when => {
-# :provider => lambda { |context| "a value" },
-# :injected_into => ServiceB,
-# :target_has => AnAttribute,
-# :member_has => AnAttribute,
-# :class_has => AnAttribute
-# ]
-#end
-
-# Step 2: Sprinkle sugar :)
-#to_configure_ninject do |ninject|
-# ninject.bind IServiceA, :to => ServiceA, :as => :singleton do
-# meta { :type => "superservice" },
-# name "aaaaa",
-# with :parameter => [{ :my_param => lambda { |context| "param_value" } }],
-# :constructor_arguments => [{:const_arg => 56 }],
-# :property_values => [{:property_name => 94 }],
-# on_activation { |obj| obj.do_some_work },
-# on_deativated { |obj| obj.do_some_cleanup },
-# when :provider => lambda { |context| "a value" },
-# :injected_into => ServiceB,
-# :target_has => AnAttribute,
-# :member_has => AnAttribute,
-# :class_has => AnAttribute
-#
-#end

0 comments on commit 3a2c9c8

Please sign in to comment.
Something went wrong with that request. Please try again.