Skip to content

Commit e636680

Browse files
committed
favor an already instantiated instance of ElasticInferer on settings instead of newing one everytime in various places
1 parent bc7fc17 commit e636680

File tree

9 files changed

+13
-8
lines changed

9 files changed

+13
-8
lines changed

src/Nest/DSL/Paths/DocumentOptionalPathDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void SetRouteParameters<TParameters>(
3131
ElasticsearchPathInfo<TParameters> pathInfo)
3232
where TParameters : IRequestParameters, new()
3333
{
34-
var inferrer = new ElasticInferrer(settings);
34+
var inferrer = settings.Inferrer;
3535

3636
pathInfo.Index = inferrer.IndexName(path.Index);
3737
pathInfo.Type = inferrer.TypeName(path.Type);
@@ -45,7 +45,7 @@ public static void SetRouteParameters<TParameters, T>(
4545
where TParameters : IRequestParameters, new()
4646
where T : class
4747
{
48-
var inferrer = new ElasticInferrer(settings);
48+
var inferrer = settings.Inferrer;
4949

5050
var index = path.Index != null ? inferrer.IndexName(path.Index) : inferrer.IndexName<T>();
5151
var type = path.Type != null ? inferrer.TypeName(path.Type) : inferrer.TypeName<T>();

src/Nest/DSL/Paths/FixedIndexTypePathDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void SetRouteParameters<TParameters>(
2121
ElasticsearchPathInfo<TParameters> pathInfo)
2222
where TParameters : IRequestParameters, new()
2323
{
24-
var inferrer = new ElasticInferrer(settings);
24+
var inferrer = settings.Inferrer;
2525
var index = inferrer.IndexName(path.Index);
2626
var type = inferrer.TypeName(path.Type);
2727

src/Nest/DSL/Visitor/DslPrettyPrintVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public string PrettyPrint
2525
public DslPrettyPrintVisitor(IConnectionSettingsValues settings)
2626
{
2727
this._sb = new StringBuilder();
28-
this._infer = new ElasticInferrer(settings);
28+
this._infer = settings.Inferrer;
2929
}
3030

3131
public virtual int Depth { get; set; }

src/Nest/Domain/Connection/ConnectionSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ string IConnectionSettingsValues.DefaultIndex
6464
}
6565
}
6666

67+
private ElasticInferrer _inferrer;
68+
ElasticInferrer IConnectionSettingsValues.Inferrer { get { return _inferrer; } }
69+
6770
private Func<Type, string> _defaultTypeNameInferrer;
6871
Func<Type, string> IConnectionSettingsValues.DefaultTypeNameInferrer { get { return _defaultTypeNameInferrer; } }
6972

@@ -97,6 +100,7 @@ public ConnectionSettings(IConnectionPool connectionPool, string defaultIndex) :
97100

98101
this._modifyJsonSerializerSettings = (j) => { };
99102
this._contractConverters = Enumerable.Empty<Func<Type, JsonConverter>>().ToList().AsReadOnly();
103+
this._inferrer = new ElasticInferrer(this);
100104
}
101105
public ConnectionSettings(Uri uri, string defaultIndex)
102106
: this(new SingleNodeConnectionPool(uri ?? new Uri("http://localhost:9200")), defaultIndex)

src/Nest/Domain/Connection/IConnectionSettingsValues.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Nest
77
{
88
public interface IConnectionSettingsValues : IConnectionConfigurationValues
99
{
10+
ElasticInferrer Inferrer { get; }
1011
FluentDictionary<Type, string> DefaultIndices { get; }
1112
FluentDictionary<Type, string> DefaultTypeNames { get; }
1213
string DefaultIndex { get; }

src/Nest/Domain/Paths/FieldSelection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class FieldSelection<T> : IFieldSelection<T>
3030
private ElasticInferrer Infer { get; set; }
3131
public FieldSelection(IConnectionSettingsValues settings, IDictionary<string, object> valuesDictionary = null)
3232
{
33-
this.Infer = new ElasticInferrer(settings);
33+
this.Infer = settings.Inferrer;
3434
((IFieldSelection<T>)this).FieldValuesDictionary = valuesDictionary;
3535
}
3636

src/Nest/Domain/Responses/BaseResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ElasticInferrer Infer
7272
var settings = this.Settings;
7373
if (settings == null)
7474
return null;
75-
this._infer = new ElasticInferrer(settings);
75+
this._infer = this.Settings.Inferrer;
7676
return this._infer;
7777
}
7878
}

src/Nest/ElasticClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public ElasticClient(
5454
this.Serializer
5555
);
5656
this.RawDispatch = new RawDispatch(this.Raw);
57-
this.Infer = new ElasticInferrer(this._connectionSettings);
57+
this.Infer = this._connectionSettings.Inferrer;
5858

5959
}
6060

src/Tests/Nest.Tests.Unit/QueryParsers/Visitor/DslPrettyPrintVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public string PrettyPrint
3131
public DslPrettyPrintVisitor(IConnectionSettingsValues settings)
3232
{
3333
this._sb = new StringBuilder();
34-
this._infer = new ElasticInferrer(settings);
34+
this._infer = settings.Inferrer;
3535
}
3636

3737
public virtual int Depth { get; set; }

0 commit comments

Comments
 (0)