C# 国际奥委会';它没有被注入服务
它正在工作,然后突然停止工作。我一定做了什么。 我正在从MVC控制器调用我的服务。我正在使用NHibernate和我在这里找到的服务运行程序 Service.Session和Service.RequestContext为空C# 国际奥委会';它没有被注入服务,c#,asp.net-mvc,
servicestack,C#,Asp.net Mvc,
servicestack,它正在工作,然后突然停止工作。我一定做了什么。 我正在从MVC控制器调用我的服务。我正在使用NHibernate和我在这里找到的服务运行程序 Service.Session和Service.RequestContext为空 public class AppHost : AppHostBase { static ILog log; //Tell ServiceStack the name and where to find your web services public
public class AppHost : AppHostBase
{
static ILog log;
//Tell ServiceStack the name and where to find your web services
public AppHost() : base("Play it Forward", typeof(GiveawayService).Assembly)
{
LogManager.LogFactory = new Log4NetFactory();
log = LogManager.GetLogger(typeof(AppHost));
// This is a singleton NHibernate session factory.
Container.Register(SessionManager.SessionFactory);
}
public override void Configure(Container container)
{
SetConfig(
new EndpointHostConfig
{
GlobalResponseHeaders =
{
{ "Access-Control-Allow-Origin", "*" },
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
},
EnableFeatures = Feature.All.Remove(GetDisabledFeatures()),
ServiceStackHandlerFactoryPath = "api"
});
var appSettings = new AppSettings();
Plugins.Add(
new AuthFeature(
() => new SteamUserSession(),
new IAuthProvider[] { new SteamOpenIdOAuthProvider(appSettings) }));
Plugins.Add(new SessionFeature());
container.Register<ICacheClient>(c => new MemoryCacheClient());
// TODO: Implement Redis
//container.Register<ICacheClient>(c => new BasicRedisClientManager());
container.RegisterAutoWired<GiveawayService>();
container.RegisterAutoWired<UserService>();
container.RegisterAutoWired<SecureUserService>();
container.RegisterAutoWired<GamesService>();
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();
log.InfoFormat("AppHost Configured: {0}", DateTime.Now);
}
public override IServiceRunner<TRequest> CreateServiceRunner<TRequest>(ActionContext actionContext)
{
return new BaseServiceRunner<TRequest>(this, actionContext);
}
}
公共类AppHost:AppHostBase
{
静态ILog测井;
//告诉ServiceStack您的web服务的名称和位置
public AppHost():base(“向前播放”,类型为(GiveawayService.Assembly)
{
LogManager.LogFactory=新的Log4NetFactory();
log=LogManager.GetLogger(typeof(AppHost));
//这是一个单一的NHibernate会话工厂。
Container.Register(SessionManager.SessionFactory);
}
公共覆盖无效配置(容器)
{
设置配置(
新端点主机配置
{
全球负责人=
{
{“访问控制允许来源”,“*”},
{“访问控制允许方法”、“获取、发布、放置、删除、选项”},
},
EnableFeatures=Feature.All.Remove(GetDisabledFeatures()),
ServiceStackHandlerFactoryPath=“api”
});
var appSettings=新的appSettings();
插件。添加(
新AuthFeature(
()=>新的SteamUserSession(),
新的IAuthProvider[]{new SteamOpenIdOAuthProvider(appSettings)});
Add(newsessionfeature());
Register(c=>newmemorycacheclient());
//TODO:实现Redis
//Register(c=>newbasicredisclientmanager());
container.RegisterAutoWired();
container.RegisterAutoWired();
container.RegisterAutoWired();
container.RegisterAutoWired();
ControllerBuilder.Current.SetControllerFactory(新的FunqControllerFactory(container));
ServiceStackController.CatchAllController=reqCtx=>container.TryResolve();
InfoFormat(“AppHost配置:{0}”,DateTime.Now);
}
公共覆盖IServiceRunner CreateServiceRunner(ActionContext ActionContext)
{
返回新的BaseServiceRunner(此,actionContext);
}
}
这是我的一项服务,我遇到了问题
public object Get(FindClosedGiveaways request)
{
if (request.Take > 50 || request.Take == null)
{
request.Take = 50;
}
if (request.StartIndex == null)
{
request.StartIndex = 0;
}
//return RequestContext.ToOptimizedResultUsingCache(
// base.Cache,
// cacheKey,
// TimeSpan.FromMinutes(15),
// () =>
// {
var session = RequestContext.GetItem("session") as ISession;
IQueryable<Entities.Giveaway> q =
session.Query<Entities.Giveaway>()
.Fetch(x => x.Giveable)
.Fetch(x => x.User)
.Fetch(x => x.Winner)
.Where(x => x.EndDate > DateTime.UtcNow.Subtract(new TimeSpan, 0, 0, 0)));
if (request.UserSteamID != null)
{
q = q.Where(x => request.UserSteamID == x.User.SteamID);
}
else if (request.UserID != null)
{
q = q.Where(x => request.UserID == x.User.ID);
}
q = q.OrderByDescending(x => x.EndDate).Skip(request.StartIndex.Value).Take(request.Take.Value);
List<GiveawaySummary> list = q.ConvertAll(
x =>
{
// If GiveawaySummary contains another class as a property, it
var giv = x.TranslateTo<GiveawaySummary>();
giv.GifterUsername = x.User.Username;
giv.GifterSteamID = x.User.SteamID;
giv.WinnerUsername = x.Winner.Username;
giv.WinnerSteamID = x.Winner.SteamID;
if (x.Giveable.Type == "PiF.Entities.Subscription")
{
giv.Subscription = x.Giveable.TranslateTo<Subscription>();
}
else
{
giv.App = x.Giveable.TranslateTo<App>();
}
return giv;
});
return list;
//});
}
public object Get(FindClosedGiveaways请求)
{
if(request.Take>50 | | request.Take==null)
{
请求。取=50;
}
if(request.StartIndex==null)
{
request.StartIndex=0;
}
//return RequestContext.ToOptimizedResultUsingCache(
//base.Cache,
//cacheKey,
//时间跨度从分钟(15),
// () =>
// {
var session=RequestContext.GetItem(“session”)作为ISession;
可液化q=
session.Query()
.Fetch(x=>x.givable)
.Fetch(x=>x.User)
.Fetch(x=>x.Winner)
其中(x=>x.EndDate>DateTime.UtcNow.Subtract(新的时间跨度,0,0));
if(request.UserSteamID!=null)
{
q=q.Where(x=>request.userstreamid==x.User.streamid);
}
else if(request.UserID!=null)
{
q=q.Where(x=>request.UserID==x.User.ID);
}
q=q.OrderByDescending(x=>x.EndDate).Skip(request.StartIndex.Value).Take(request.Take.Value);
列表=q.ConvertAll(
x=>
{
//如果GiveawaySummary包含另一个类作为属性,则
var giv=x.TranslateTo();
giv.GifterUsername=x.User.Username;
giv.GifterSteamID=x.User.SteamID;
giv.WinnerUsername=x.Winner.Username;
giv.WinnerSteamID=x.Winner.SteamID;
if(x.givable.Type==“PiF.Entities.Subscription”)
{
giv.Subscription=x.givable.TranslateTo();
}
其他的
{
giv.App=x.givable.TranslateTo();
}
返回giv;
});
退货清单;
//});
}
关于“停止工作”的更多信息会很好。是否只是暂停,是否有任何错误消息?目前的国际奥委会的正常行为是什么(尽可能准确)?我的意思是,它过去的工作环境应该由国际奥委会注入,而现在由于某种原因,它不是。我卸载了所有nuget软件包,并重新安装了它们。为了访问RequestContext
,您需要确保您的服务实现iRequestRequestContext
。该接口不仅提供了实际的RequestContext
属性,还向ServiceStack发出信号,将当前的RequestContext
注入服务。我相信,如果您的服务继承自ServiceStack的服务
类,那么应该注意这一点。我的服务确实实现了服务。它起作用了,我一定是做了什么导致它的。我确实安装了AutoFunq nuget软件包,但我卸载了它。当我发现它坏了的时候,我在代码里到处都是。它并没有注入它应该有的一些属性。这个问题是出现在所有的服务中还是只出现在这个服务中?