Skip to content

Commit b308601

Browse files
committed
Added a mechanism for adding a custom IComponentMappingProvider implementation to a class mapping. Requested by Brandon Behrens.
1 parent 74a9b3c commit b308601

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
@@ -284,6 +284,19 @@ protected virtual ComponentPart<TComponent> Component<TComponent>(Member propert
284284
return part;
285285
}
286286

287+
/// <summary>
288+
/// Allows the user to add a custom component mapping to the class mapping.
289+
/// Note: not a fluent method.
290+
/// </summary>
291+
/// <remarks>
292+
/// In some cases, our users need a way to add an instance of their own implementation of IComponentMappingProvider.
293+
/// 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
294+
/// </remarks>
295+
public void Component(IComponentMappingProvider componentProvider)
296+
{
297+
components.Add(componentProvider);
298+
}
299+
287300
#region HasMany
288301

289302
private OneToManyPart<TChild> MapHasMany<TChild, TReturn>(Expression<Func<T, TReturn>> expression)

0 commit comments

Comments
 (0)