Let’s say I’ve got some fluently configured NHibernate settings, which is using both Fluent mappings and Automappings.
Configuration = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.ShowSql().InMemory)
.Mappings(x =>
{
x.FluentMappings.AddFromAssemblyOf<RepositoryEntity>();
x.AutoMappings.Add(autoPersistenceModel);
});
Now – is it possible to check that some arbitrary type T is mapped (or not mapped) to this configuration?
I am attempting to make some bulletproof repository and I think this moment is kind of crucial.
Thank you
Yes. After creating your SessionFactory, keep the Configuration around, and set up this method in your repository:
AFAIK this can be used to detect both fluently- and XML-mapped classes. You may need to compare more closely if you have similarly-named classes in different namespaces, but this should get you started.
Something you may also be able to use in developing a “bulletproof” Repo is the EntityNotFoundDelegate, which allows you to define a custom method for dealing with entities given to a repository for which it doesn’t have a mapping. You could, potentially, use this to ask another repository if it can handle the entity, or kick it back to a Strategy pattern that may have several possible repos to try.