无法实例化 SessionProvider
Could not Instantiate SessionProvider
我正在使用 UConnector 下载订单和更新状态。实际下载按预期工作,但当我尝试更新状态时收到错误消息。我已经评论了导致代码错误的行。我希望有人能告诉我我错过了什么?
我的Component.config
<configuration>
<components>
<component
id="SessionProvider"
service="UCommerce.EntitiesV2.ISessionProvider, UCommerce"
type="UCommerce.EntitiesV2.SessionProvider, UCommerce"/>
<component id="UCommerce.DataMappingsTag"
service="UCommerce.EntitiesV2.IContainsNHibernateMappingsTag, UCommerce"
type="UCommerce.EntitiesV2.MappingAssemblyTag, UCommerce"/>
<component id="OrderService"
service="UCommerce.Transactions.IOrderService, UCommerce"
type="UCommerce.Transactions.OrderService, UCommerce"/>
<component id="Repository"
service="UCommerce.EntitiesV2.IRepository`1, UCommerce"
type="UCommerce.EntitiesV2.Repository`1, UCommerce"/>
</components>
</configuration>
代码
var orderService = ObjectFactory.Instance.Resolve<IOrderService>();
//var newOrderStatus = OrderStatus.Get((int)OrderStatusCode.Processing); //This line
var newOrderStatus = OrderStatus.All().SingleOrDefault(x => x.Name == "Processing"); //OR this line give the same error
orderService.ChangeOrderStatus(item, newOrderStatus);
错误:
ComponentActivator: could not instantiate
UCommerce.EntitiesV2.SessionProvider
内部异常:
{"No component for supporting the service
UCommerce.Infrastructure.Configuration.CommerceConfigurationProvider
was found"}
堆栈跟踪:
at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate
constructor, Object[] arguments, Type implType) at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext
context, ConstructorCandidate constructor, Object[] arguments) at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context) at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context) at
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context, Burden burden) at
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext
context, Boolean trackedExternally) at
Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>n__FabricatedMethod3(CreationContext
, Boolean ) at
Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>c__DisplayClass1.b__0(Action1
afterCreated) at
Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel
model, ScopedInstanceActivationCallback createInstance) at
Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext
context, IReleasePolicy releasePolicy) at
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext
context, Boolean requiresDecommission, Boolean instanceRequired,
Burden& burden) at
Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext
context, Boolean instanceRequired) at
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext
context) at
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext
context, ComponentModel model, DependencyModel dependency) at
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext
context, ComponentModel model, DependencyModel dependency) at
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext
context, ISubDependencyResolver contextHandlerResolver, ComponentModel
model, DependencyModel dependency) at
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext
context, ISubDependencyResolver contextHandlerResolver, ComponentModel
model, DependencyModel dependency) at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate
constructor, CreationContext context) at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context) at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context) at
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context, Burden burden) at
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext
context, Boolean trackedExternally) at
Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>n__FabricatedMethod3(CreationContext
, Boolean ) at
Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>c__DisplayClass1.b__0(Action
1
afterCreated) at
Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel
model, ScopedInstanceActivationCallback createInstance) at
Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext
context, IReleasePolicy releasePolicy) at
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext
context, Boolean requiresDecommission, Boolean instanceRequired,
Burden& burden) at
Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext
context, Boolean instanceRequired) at
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext
context) at
Castle.MicroKernel.Handlers.DefaultGenericHandler.Resolve(CreationContext
context, Boolean instanceRequired) at
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext
context) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler
handler, Type service, IDictionary additionalArguments, IReleasePolicy
policy) at
Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type
service, IDictionary arguments, IReleasePolicy policy) at
Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary
arguments) at Castle.Windsor.WindsorContainer.ResolveT at
UCommerce.Infrastructure.ObjectFactory.ResolveT at
UCommerce.EntitiesV2.OrderStatus.GetRepo() at
UCommerce.EntitiesV2.OrderStatus.All() at
SiteConnector.Classes.OrdersListToCalClub.Send(IEnumerable`1 input)
我发现您实际上需要比您想象的更多的 dll。
这是我包含的两个屏幕截图(项目中的引用和 lib 文件夹)。我正在与 sitecore 集成,但你可以用我想的 Umbracco 对应物替换那些 dll。
这是我用来更新订单状态的代码。在我的例子中,该列表包含订单(我将列表保存在 Azure 存储中,因此您也会看到一些 dll)。
ISession session = new SessionProvider("connectionstring").GetSession();
OrderStatus status = session.Query<OrderStatus>().FirstOrDefault(os => os.Name.Equals("Processing"));
foreach (PurchaseOrder order in list.Select(o => o.PurchaseOrder))
{
order.OrderStatus = status;
session.Save(order);
}
session.Flush();
这会将采购订单更新为它在 ord.OrderStatusName
中找到的任何状态。此外,我发现如果您正在处理超过 200 条记录,不清除会话会大大降低速度。
foreach (CcOrder ord in input)
{
PurchaseOrder poOrder =
_session.Query<PurchaseOrder>().FirstOrDefault(p => p.OrderNumber == ord.OrderId);
OrderStatus newOrderStatus = _session.Query<OrderStatus>().FirstOrDefault(p => p.Name == ord.OrderStatusName);
if (poOrder == null || newOrderStatus == null) continue; //If one or both not found go to next
poOrder.OrderStatus = newOrderStatus;
_session.Save(poOrder);
_session.Flush();
_session.Clear();
}
我正在使用 UConnector 下载订单和更新状态。实际下载按预期工作,但当我尝试更新状态时收到错误消息。我已经评论了导致代码错误的行。我希望有人能告诉我我错过了什么?
我的Component.config
<configuration>
<components>
<component
id="SessionProvider"
service="UCommerce.EntitiesV2.ISessionProvider, UCommerce"
type="UCommerce.EntitiesV2.SessionProvider, UCommerce"/>
<component id="UCommerce.DataMappingsTag"
service="UCommerce.EntitiesV2.IContainsNHibernateMappingsTag, UCommerce"
type="UCommerce.EntitiesV2.MappingAssemblyTag, UCommerce"/>
<component id="OrderService"
service="UCommerce.Transactions.IOrderService, UCommerce"
type="UCommerce.Transactions.OrderService, UCommerce"/>
<component id="Repository"
service="UCommerce.EntitiesV2.IRepository`1, UCommerce"
type="UCommerce.EntitiesV2.Repository`1, UCommerce"/>
</components>
</configuration>
代码
var orderService = ObjectFactory.Instance.Resolve<IOrderService>();
//var newOrderStatus = OrderStatus.Get((int)OrderStatusCode.Processing); //This line
var newOrderStatus = OrderStatus.All().SingleOrDefault(x => x.Name == "Processing"); //OR this line give the same error
orderService.ChangeOrderStatus(item, newOrderStatus);
错误:
ComponentActivator: could not instantiate UCommerce.EntitiesV2.SessionProvider
内部异常:
{"No component for supporting the service UCommerce.Infrastructure.Configuration.CommerceConfigurationProvider was found"}
堆栈跟踪:
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>n__FabricatedMethod3(CreationContext , Boolean ) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>c__DisplayClass1.b__0(Action
1 afterCreated) at Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>n__FabricatedMethod3(CreationContext , Boolean ) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.<>c__DisplayClass1.b__0(Action
1 afterCreated) at Castle.MicroKernel.Lifestyle.Scoped.DefaultLifetimeScope.GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance) at Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) at Castle.MicroKernel.Handlers.DefaultGenericHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments) at Castle.Windsor.WindsorContainer.ResolveT at UCommerce.Infrastructure.ObjectFactory.ResolveT at UCommerce.EntitiesV2.OrderStatus.GetRepo() at UCommerce.EntitiesV2.OrderStatus.All() at SiteConnector.Classes.OrdersListToCalClub.Send(IEnumerable`1 input)
我发现您实际上需要比您想象的更多的 dll。 这是我包含的两个屏幕截图(项目中的引用和 lib 文件夹)。我正在与 sitecore 集成,但你可以用我想的 Umbracco 对应物替换那些 dll。
这是我用来更新订单状态的代码。在我的例子中,该列表包含订单(我将列表保存在 Azure 存储中,因此您也会看到一些 dll)。
ISession session = new SessionProvider("connectionstring").GetSession();
OrderStatus status = session.Query<OrderStatus>().FirstOrDefault(os => os.Name.Equals("Processing"));
foreach (PurchaseOrder order in list.Select(o => o.PurchaseOrder))
{
order.OrderStatus = status;
session.Save(order);
}
session.Flush();
这会将采购订单更新为它在 ord.OrderStatusName
中找到的任何状态。此外,我发现如果您正在处理超过 200 条记录,不清除会话会大大降低速度。
foreach (CcOrder ord in input)
{
PurchaseOrder poOrder =
_session.Query<PurchaseOrder>().FirstOrDefault(p => p.OrderNumber == ord.OrderId);
OrderStatus newOrderStatus = _session.Query<OrderStatus>().FirstOrDefault(p => p.Name == ord.OrderStatusName);
if (poOrder == null || newOrderStatus == null) continue; //If one or both not found go to next
poOrder.OrderStatus = newOrderStatus;
_session.Save(poOrder);
_session.Flush();
_session.Clear();
}