Skip to content

Commit 0683385

Browse files
paulbatumjagregory
authored andcommitted
Added a mechanism for adding a custom IComponentMappingProvider implementation to a class mapping. Requested by Brandon Behrens.
1 parent e5fc13e commit 0683385

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using System;
12
using System.Collections;
3+
using FluentNHibernate.Mapping;
4+
using FluentNHibernate.Mapping.Providers;
25
using FluentNHibernate.MappingModel.ClassBased;
36
using FluentNHibernate.Specs.FluentInterface.Fixtures;
47
using Machine.Specifications;
@@ -25,6 +28,24 @@ public class when_class_map_is_told_to_map_a_component_from_a_field : ProviderSp
2528
protected static ClassMapping mapping;
2629
}
2730

31+
public class when_class_map_is_told_to_map_a_component_using_a_provider : ProviderSpec
32+
{
33+
Because of = () =>
34+
mapping = map_as_class<EntityWithComponent>(m => m.Component(new ComponentMappingProviderStub()));
35+
36+
Behaves_like<ClasslikeComponentBehaviour> a_component_in_a_classlike;
37+
38+
protected static ClassMapping mapping;
39+
40+
private class ComponentMappingProviderStub : IComponentMappingProvider
41+
{
42+
public IComponentMapping GetComponentMapping()
43+
{
44+
return null;
45+
}
46+
}
47+
}
48+
2849
public class when_class_map_is_told_to_map_a_component_using_reveal : ProviderSpec
2950
{
3051
Because of = () =>

src/FluentNHibernate/Mapping/ClasslikeMapBase.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,19 @@ protected virtual ComponentPart<TComponent> Component<TComponent>(Member propert
278278
return part;
279279
}
280280

281+
/// <summary>
282+
/// Allows the user to add a custom component mapping to the class mapping.
283+
/// Note: not a fluent method.
284+
/// </summary>
285+
/// <remarks>
286+
/// In some cases, our users need a way to add an instance of their own implementation of IComponentMappingProvider.
287+
/// For an example of where this might be necessary, see: http://codebetter.com/blogs/jeremy.miller/archive/2010/02/16/our-extension-properties-story.aspx
288+
/// </remarks>
289+
public void Component(IComponentMappingProvider componentProvider)
290+
{
291+
components.Add(componentProvider);
292+
}
293+
281294
private OneToManyPart<TChild> MapHasMany<TChild, TReturn>(Expression<Func<T, TReturn>> expression)
282295
{
283296
return HasMany<TChild>(expression.ToMember());

0 commit comments

Comments
 (0)