I need to use the `Ninject.Extensions.Factory` to generate the constructor 
of internal classes. Follow one example:

    using Ninject.Extensions.Conventions;
    using Ninject.Modules;
    using Ninject.Extensions.Factory;
    
    namespace ClassLibrary
    {
        using System;
    
        namespace ClassLibrary
        {
            internal class Class1
            {
                public void Print(string message)
                {
                    Console.WriteLine(message);
                }
            }
    
            internal interface IClass1Factory
            {
                Class1 Create();
            }
    
            public interface IInterface2
            {
                void PrintMessage();
            }
            internal class Class2 : IInterface2
            {
                private readonly IClass1Factory _class1Factory;
    
                public Class2(IClass1Factory class1Factory)
                {
                    _class1Factory = class1Factory;
                }
    
                public void PrintMessage()
                {
                    Class1 class1 = _class1Factory.Create();
                    class1.Print("Class2's IInterface2 'PrintMessage' 
implementation.");
                }
            }
    
            public class MyNinjectModule : NinjectModule
            {
                public override void Load()
                {
                    Kernel.Bind(r => r
                    .FromThisAssembly()
                    .IncludingNonePublicTypes()
                    .SelectAllClasses()
                    .BindAllInterfaces());
                    
                    Kernel.Bind<IClass1Factory>().ToFactory();
                }
            }
        }
    }


Application using the library:

    using ClassLibrary.ClassLibrary;
    using Ninject;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                IKernel kernel = new StandardKernel();
                kernel.Load<MyNinjectModule>();
                IInterface2 interface2 = kernel.Get<IInterface2>();
                interface2.PrintMessage();
            }
        }
    }

Even after include `[assembly: 
InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]` I'm 
getting the following run tine error:

> {"Type 'Castle.Proxies.IClass1FactoryProxy' from assembly
> 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
> PublicKeyToken=null' is attempting to implement an inaccessible
> interface.":""}

Any idea how to fix this?

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to castle-project-users+unsubscr...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to