/// <summary> /// Creates a background service using the specified <paramref name="factoryExpression"/>. /// </summary> /// <typeparam name="TFactory"></typeparam> /// <typeparam name="TService"></typeparam> /// <param name="webWorkerProxy"></param> /// <param name="factoryExpression"></param> /// <param name="workerInitOptionsModifier"></param> /// <returns></returns> public static async Task <IWorkerBackgroundService <TService> > CreateBackgroundServiceUsingFactoryAsync <TFactory, TService>( this IWorker webWorkerProxy, Expression <Func <TFactory, TService> > factoryExpression, Action <WorkerInitOptions> workerInitOptionsModifier = null) where TFactory : class where TService : class { if (webWorkerProxy is null) { throw new ArgumentNullException(nameof(webWorkerProxy)); } if (factoryExpression is null) { throw new ArgumentNullException(nameof(factoryExpression)); } var workerInitOptions = new WorkerInitOptions(); if (workerInitOptionsModifier == null) { workerInitOptions.AddAssemblyOf <TService>(); } else { workerInitOptionsModifier(workerInitOptions); } var factoryProxy = new WorkerBackgroundServiceProxy <TFactory>(webWorkerProxy, new WebWorkerOptions()); await factoryProxy.InitAsync(workerInitOptions); var newProxy = await factoryProxy.InitFromFactoryAsync(factoryExpression); newProxy.Disposables.Add(factoryProxy); return(newProxy); }
public static async Task <IWorkerBackgroundService <T> > CreateBackgroundServiceAsync <T>(this IWorker webWorkerProxy, WorkerInitOptions workerInitOptions = null) where T : class { var proxy = new WorkerBackgroundServiceProxy <T>(webWorkerProxy, new WebWorkerOptions()); if (workerInitOptions == null) { workerInitOptions = new WorkerInitOptions().AddAssemblyOf <T>(); } await proxy.InitAsync(workerInitOptions); return(proxy); }
public static async Task <IWorkerBackgroundService <T> > CreateBackgroundServiceAsync <T>(this IWorker webWorkerProxy, WorkerInitOptions workerInitOptions = null) where T : class { var proxy = new WorkerBackgroundServiceProxy <T>(webWorkerProxy, new WebWorkerOptions()); if (workerInitOptions == null) { workerInitOptions = new WorkerInitOptions() { // Takes a (not so) wild guess and sets the dll name to the assembly name DependentAssemblyFilenames = new[] { $"{typeof(T).Assembly.GetName().Name}.dll" } }; } await proxy.InitAsync(workerInitOptions); return(proxy); }