Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:08:00+00:00 2026-05-11T01:08:00+00:00

I don’t know if this is too specific a question, if that is possible,

  • 0

I don’t know if this is too specific a question, if that is possible, but I’m having to port an app that uses Castle Windsor to Unity so that there isn’t a reliance on non-microsoft approved libraries. I know I know but what are you going to do.

Anyway I’ve managed it but I’m not happy with what I’ve got. In Windsor I had this:

Register(             AllTypes.Of(typeof(AbstractPresenter<>)).FromAssemblyNamed('Links.Mvp'),             AllTypes.Of(typeof(IView)).FromAssemblyNamed('Links.WinForms').WithService.FromInterface()); 

which I’ve converted to this in unity

RegisterType<IMainView, MainView>();         RegisterType<IConfigureLinkView, ConfigureLinkView>();         RegisterType<IConfigureSourceView, ConfigureSourceView>();         RegisterType<IConfigureSinkView, ConfigureSinkView>();         RegisterType<MainPresenter, MainPresenter>();         RegisterType<ConfigureLinkPresenter, ConfigureLinkPresenter>();         RegisterType<ConfigureSourcePresenter, ConfigureSourcePresenter>();         RegisterType<ConfigureSinkPresenter, ConfigureSinkPresenter>(); 

As you can see I’m having to register every single thing rather than be able to use some sort of auto-configuration. So my question is: is there a better way of doing this in unity?

Thanks,

Adam.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:08:00+00:00Added an answer on May 11, 2026 at 1:08 am

    Cool. This feature is not in unity yet but if you felt a bit ambitious you could setup your own convention based registration. Found below is a snipped that works for the executing assembly and interfaces. Good luck.

    P.S. This feels like a big hack, I would probably continue just registering all types by hand.

    using System; using System.Collections.Generic; using System.Linq; using System.Text;  using System.Reflection;  namespace Forum {     class Program     {         static void Main(string[] args)         {             // get your assemblies and types you can register             Assembly a = Assembly.GetExecutingAssembly();             var types = a.GetTypes();                         var bindTo = from t in types                          where t.IsAbstract || t.IsInterface                          select t;              // apply your conventions to filter our types to be registered             var interfacePairs = from t in bindTo.Where(x => x.IsInterface)                                  let match = types.FirstOrDefault(x => x.Name ==     t.Name.Substring(1))                                  where match != null                                  select new Pair { To = t, From = match };             var abstractPairs = new Pair[] {};               // setup the generic form of the method to register the types             var thisType = typeof(Program);             var bindings = BindingFlags.Static | BindingFlags.Public;             MethodInfo genericMethod = thisType.GetMethod('RegisterType', bindings);                          // register all your types by executing the              // specialized generic form of the method             foreach (var t in interfacePairs.Concat(abstractPairs))             {                 Type[] genericArguments = new Type[] { t.To, t.From };                 MethodInfo method = genericMethod.MakeGenericMethod(genericArguments);                 method.Invoke(null, new object [] {});             }              Console.ReadKey();         }          public static void RegisterType<To, From>()         {             Console.WriteLine('Register { To: {0} From: {1} }', typeof(To), typeof(From));         }          // Test classes that should be picked up         interface ITest { }         class Test : ITest { }          class Pair         {             public Type To { get; set; }             public Type From { get; set; }         }             } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The answer is no. You can only source a Uri,… May 11, 2026 at 8:38 am
  • added an answer Go right ahead. Just put your extra attributes into a… May 11, 2026 at 8:38 am
  • added an answer Here's a nice example: CodeProject: Adding Glass Effect to WPF… May 11, 2026 at 8:38 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.

      Related Questions

      No related questions found