Access level of mapping classes

Original Post Stefan's Avatar

Stefan

25 Feb, 2010 10:33 AM via web

Is there a reason why FluentMappings.AddFromAssembly() doesn't add classes with internal access?

Side note: the method responsible for this is actually FluentNHibernate.PersistenceModel.AddMappingsFromAssembly(). It uses Assembly.GetExportedTypes() method, which gets the public types and public nested types of public types.

I'd like to make mapping classes internal - no need to expose them. But then I have to add every mapping separatelly with FluentMappings.Add(). Is there another way to add all types at once?

PS. Thanks for FHN! A fantastic tool!

  1. Support Staff 2 Posted by Paul Batum on 28 Feb, 2010 01:17 PM

    Paul Batum's Avatar

    If you look at persistence model, there is another method called AddMappingsFromSource, which takes an ITypeSource. It should be trivial to make your own type source and pass it through.

    public class MyAssemblyTypeSource : ITypeSource
    {
        private readonly Assembly source;
    
        public AssemblyTypeSource(Assembly source)
        {
            this.source = source;
        }
    
        public IEnumerable<Type> GetTypes()
        {
            return source.GetTypes();
        }
    }
    

    And then:

    Assembly yourMappingAssembly = ....
    
    ...
    
    m.FluentMappings.PersistenceModel.AddMappingsFromSource(new MyAssemblyTypeSource(yourMappingAssembly));
    
  2. James Gregory resolved this discussion on 18 Mar, 2010 12:17 PM.

Comments are currently closed for this discussion. You can start a new one.

Recent Discussions

05 Jul, 2010 10:29 PM
05 Jul, 2010 12:45 PM
05 Jul, 2010 12:42 PM
05 Jul, 2010 12:17 PM
05 Jul, 2010 12:12 PM

 

03 Jul, 2010 12:26 AM
02 Jul, 2010 02:17 PM
02 Jul, 2010 08:18 AM
02 Jul, 2010 12:20 AM
01 Jul, 2010 10:14 PM