[Ironruby-core] problem

Ivan Porto Carrero ivan at flanders.co.nz
Wed Mar 18 14:50:26 EDT 2009


You can try using the LoadAssembly method on the runtime object

runtime.LoadAssembly(typeof(IWindsorContainer).Assembly);

that should require the assembly a little nicer

I think you can also use load_assembly 'Castle.Windsor'

http://github.com/casualjim/ninject-dynamic/blob/0b531d9e3ae46cc3e8549c9cfc078a8c27e5dda7/src/Ninject.Dynamic/RubyEngine.cs#L166
http://github.com/casualjim/ninject-dynamic/blob/0b531d9e3ae46cc3e8549c9cfc078a8c27e5dda7/src/Ninject.Dynamic/RubyEngine.cs#L142
http://github.com/casualjim/ninject-dynamic/blob/0b531d9e3ae46cc3e8549c9cfc078a8c27e5dda7/src/Ninject.Dynamic/RubyEngine.cs#L90



2009/3/18 Nathan Stott <nrstott at gmail.com>

> I'm using the hosting API.
> This is the entire method:
> public void Load(IWindsorContainer container, TextReader reader)
>  {
> var runtime = Ruby.CreateRuntime();
> ScriptEngine engine = Ruby.GetEngine(runtime);
>  var ctx = Ruby.GetExecutionContext(runtime);
> ctx.DefineReadOnlyGlobalVariable("container", container);
>
> string header =
> @"require 'Castle.Windsor'
> require 'Castle.MicroKernel'
> require 'Castle.Core'
>
> ComponentRegistration =
> Castle::MicroKernel::Registration::ComponentRegistration
> ComponentModel = Castle::Core::ComponentModel
> Parameter = Castle::MicroKernel::Registration::Parameter
> Component = Castle::MicroKernel::Registration::Component
>
> def component(options)
> throw :classIsRequired if !options.has_key?(:class)
>  klass = options[:class].to_clr_type
>  if options.has_key?(:service)
> service = options[:service].to_clr_type
> else
>  service = klass
> end
>  if options.has_key?(:name)
> name = options[:name]
> else
>  name = klass.class.name.underscore.lowercase
> end
>  model = ComponentModel.new(name, service, klass)
>  if options.has_key?(:parameters)
>  parameters = options[:parameters]
> parameters.each do |p|
> model.Parameters.Add(p.key, p.value)
>  end
> end
>  $container.Register(ComponentRegistration.new(model))
> end";
>
> ScriptSource headerSource = engine.CreateScriptSourceFromString(header);
>  headerSource.Execute();
>
> string containerScript = reader.ReadToEnd();
>  ScriptSource source =
> engine.CreateScriptSourceFromString(containerScript);
> source.Execute();
>  }
> }
>
> 2009/3/18 Tomas Matousek <Tomas.Matousek at microsoft.com>
>
>>  How do you run this script? From command line (ir.exe script.rb) or do
>> you use hosting API?
>>
>>
>>
>> Tomas
>>
>>
>>
>> *From:* ironruby-core-bounces at rubyforge.org [mailto:
>> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Nathan Stott
>> *Sent:* Wednesday, March 18, 2009 8:33 AM
>> *To:* ironruby-core at rubyforge.org
>> *Subject:* [Ironruby-core] problem
>>
>>
>>
>> Hi all.  I have a question that probably belongs on a users mailing list
>> but I could not find one.
>>
>>
>>
>> I get the following error when trying to use my IronRuby windsor
>> registration script:
>>
>> *
>> System.InvalidOperationException: can't convert Castle::Core::ComponentModel into Castle::Core::ComponentModel
>> *
>>
>>
>>
>> I assume this has something to do with the fact that newing up an object
>> in IronRuby isn't the same thing as newing it up in C#.
>>
>>
>>
>> Any suggestions or guidance would be appreciated.
>>
>>
>>
>> Here is the important IronRuby code:
>>
>>
>>
>> require 'Castle.Windsor'
>>
>> require 'Castle.MicroKernel'
>>
>> require 'Castle.Core'
>>
>>
>>
>> ComponentRegistration =
>> Castle::MicroKernel::Registration::ComponentRegistration
>>
>> ComponentModel = Castle::Core::ComponentModel
>>
>> Parameter = Castle::MicroKernel::Registration::Parameter
>>
>> Component = Castle::MicroKernel::Registration::Component
>>
>>
>>
>> def component(options)
>>
>>             throw :classIsRequired if !options.has_key?(:class)
>>
>>
>>
>>             klass = options[:class].to_clr_type
>>
>>
>>
>>             if options.has_key?(:service)
>>
>>                         service = options[:service].to_clr_type
>>
>>             else
>>
>>                         service = klass
>>
>>             end
>>
>>
>>
>>             if options.has_key?(:name)
>>
>>                         name = options[:name]
>>
>>             else
>>
>>                         name = klass.class.name.underscore.lowercase
>>
>>             end
>>
>>
>>
>>             model = ComponentModel.new(name, service, klass)
>>
>>
>>
>>             if options.has_key?(:parameters)
>>
>>                         parameters = options[:parameters]
>>
>>                         parameters.each do |p|
>>
>>                                     model.Parameters.Add(p.key, p.value)
>>
>>                         end
>>
>>             end
>>
>>
>>
>>             $container.Register(ComponentRegistration.new(model))
>>
>> end
>>
>>
>>
>>
>>
>> _______________________________________________
>> Ironruby-core mailing list
>> Ironruby-core at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>
>>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090318/bb61a96e/attachment.html>


More information about the Ironruby-core mailing list