<commit_before>﻿// <copyright file="AggregateRootFactory.cs" company="dddlib contributors">
//  Copyright (c) dddlib contributors. All rights reserved.
// </copyright>

#if dddlibTests
namespace dddlib.Tests.Sdk
#else
namespace dddlib.Persistence.Sdk
#endif
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using dddlib.Runtime;

    /// <summary>
    /// Represents the aggregate root factory.
    /// </summary>
    public sealed class AggregateRootFactory
    {
        /// <summary>
        /// Creates an aggregate root.
        /// </summary>
        /// <typeparam name="T">The type of aggregate root.</typeparam>
        /// <param name="memento">The memento.</param>
        /// <param name="revision">The revision.</param>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        /// <returns>The aggregate root.</returns>
        public T Create<T>(object memento, int revision, IEnumerable<object> events, string state)
            where T : AggregateRoot
        {
            var runtimeType = Application.Current.GetAggregateRootType(typeof(T));
            if (runtimeType.UninitializedFactory == null)
            {
                throw new RuntimeException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "The aggregate root of type '{0}' does not have a factory method registered with the runtime.",
                        typeof(T)));
            }<commit_msg>#51 Changed the exception message for uninitialized factories<commit_after>﻿// <copyright file="AggregateRootFactory.cs" company="dddlib contributors">
//  Copyright (c) dddlib contributors. All rights reserved.
// </copyright>

#if dddlibTests
namespace dddlib.Tests.Sdk
#else
namespace dddlib.Persistence.Sdk
#endif
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using dddlib.Runtime;

    /// <summary>
    /// Represents the aggregate root factory.
    /// </summary>
    public sealed class AggregateRootFactory
    {
        /// <summary>
        /// Creates an aggregate root.
        /// </summary>
        /// <typeparam name="T">The type of aggregate root.</typeparam>
        /// <param name="memento">The memento.</param>
        /// <param name="revision">The revision.</param>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        /// <returns>The aggregate root.</returns>
        [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Nonsense.")]
        public T Create<T>(object memento, int revision, IEnumerable<object> events, string state)
            where T : AggregateRoot
        {
            var runtimeType = Application.Current.GetAggregateRootType(typeof(T));
            if (runtimeType.UninitializedFactory == null)
            {
                throw new RuntimeException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        @"The aggregate root of type '{0}' does not have a factory method registered with the runtime.
To fix this issue, either:
- add a protected internal default constructor to the aggregate root, or
- use the bootstrapper to configure the aggregate root to reconstitute using an uninitialized factory.",
                        typeof(T)))
                {
                    HelpLink = "https://github.com/dddlib/dddlib/wiki/Aggregate-Root-Reconstitution",
                };
            }
{'fraction_non_alphanumeric': 0.11353711790393013, 'fraction_numerical': 0.002183406113537118, 'mean_word_length': 2.23477493380406, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7385614', 'n_tokens_mistral': 942, 'n_tokens_neox': 928, 'n_words': 261}