Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitOfWork"/> class.
        /// </summary>
        /// <param name="applicationContext">The application context to work in.</param>
        /// <param name="itemTypeLoader">A reference to the item type loader in use.</param>
        /// <param name="monsterTypeLoader">A reference to the monster type loader in use.</param>
        public UnitOfWork(IApplicationContext applicationContext, IItemTypesLoader itemTypeLoader, IMonsterTypesLoader monsterTypeLoader)
        {
            applicationContext.ThrowIfNull(nameof(applicationContext));

            this.applicationContext = applicationContext;

            this.databaseContextLock = new object();

            this.accounts = new Lazy <AccountRepository>(
                () =>
            {
                this.GetOrInitializeDbContext();

                return(new AccountRepository(this.databaseContext));
            },
                System.Threading.LazyThreadSafetyMode.None);

            this.characters = new Lazy <CharacterRepository>(
                () =>
            {
                this.GetOrInitializeDbContext();

                return(new CharacterRepository(this.databaseContext));
            },
                System.Threading.LazyThreadSafetyMode.None);

            this.MonsterTypes = new MonsterTypeReadOnlyRepository(monsterTypeLoader);

            this.ItemTypes = new ItemTypeReadOnlyRepository(itemTypeLoader);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationContext"/> class.
        /// </summary>
        /// <param name="options">A reference to the application configuration.</param>
        /// <param name="itemTypeLoader">A reference to the item type loader in use.</param>
        /// <param name="monsterTypeLoader">A reference to the monster type loader in use.</param>
        /// <param name="telemetryClient">A reference to the telemetry client.</param>
        /// <param name="cancellationTokenSource">A reference to the master cancellation token source.</param>
        /// <param name="dbContextGenerationFunc">A reference to a function to generate the database context.</param>
        public ApplicationContext(
            IOptions <ApplicationContextOptions> options,
            IItemTypesLoader itemTypeLoader,
            IMonsterTypesLoader monsterTypeLoader,
            TelemetryClient telemetryClient,
            CancellationTokenSource cancellationTokenSource,
            Func <IFibulaDbContext> dbContextGenerationFunc)
        {
            options.ThrowIfNull(nameof(options));
            itemTypeLoader.ThrowIfNull(nameof(itemTypeLoader));
            monsterTypeLoader.ThrowIfNull(nameof(monsterTypeLoader));
            cancellationTokenSource.ThrowIfNull(nameof(cancellationTokenSource));
            dbContextGenerationFunc.ThrowIfNull(nameof(dbContextGenerationFunc));

            DataAnnotationsValidator.ValidateObjectRecursive(options.Value);

            this.Options = options.Value;
            this.CancellationTokenSource = cancellationTokenSource;

            this.TelemetryClient = telemetryClient;

            this.itemTypeLoader            = itemTypeLoader;
            this.monsterTypeLoader         = monsterTypeLoader;
            this.contextGenerationFunction = dbContextGenerationFunc;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MonsterFilesConverter"/> class.
        /// </summary>
        /// <param name="options">The options for this converter.</param>
        /// <param name="itemTypesLoader">A reference to an item types loader to load monster inventory names.</param>
        public MonsterFilesConverter(IOptions <MonsterFilesConverterOptions> options, IItemTypesLoader itemTypesLoader)
        {
            options.ThrowIfNull(nameof(options));
            itemTypesLoader.ThrowIfNull(nameof(itemTypesLoader));

            this.options         = options.Value;
            this.itemTypesLoader = itemTypesLoader;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemTypeReadOnlyRepository"/> class.
        /// </summary>
        /// <param name="itemTypeLoader">A reference to the item type loader in use.</param>
        public ItemTypeReadOnlyRepository(IItemTypesLoader itemTypeLoader)
        {
            itemTypeLoader.ThrowIfNull(nameof(itemTypeLoader));

            if (itemTypeCatalog == null)
            {
                lock (ItemTypeCatalogLock)
                {
                    if (itemTypeCatalog == null)
                    {
                        itemTypeCatalog = itemTypeLoader.LoadTypes();
                    }
                }
            }
        }