我不是在寻求最佳实践建议,因为在互联网上有很多关于这个主题的博客文章和教程.
我问的是混乱,因为微软对整个自托管程序进行了很多改动,我找到的每个教程都采用了不同的,不赞成的或不熟悉的方法.
我的目标是在旧版Windows服务中设置自托管Web API,以控制来自非Windows客户端的各种长时间运行的任务,例如集成WCF/SOAP客户端的Android应用程序可以真正成为PITA.
我知道WCF能够提供RESTful服务这一事实,但由于Web API非常适合这样的任务,我想我试了一下.
这就是我目前使用OWIN(Katana)启动我的API的方式:
public class ApiBootstrap {
var httpConfiguration = new HttpConfiguration();
// ... configure routes etc.
appBuilder.UseWebApi(httpConfiguration); // appBuilder = IAppBuilder
var disposable = WebApp.Start<ApiBootstrapper>(_myBaseUri);
}
Run Code Online (Sandbox Code Playgroud)
但大多数教程都采用不同的方法:
var config = new HttpSelfHostConfiguration("http://localhost:999");
// ... configure routes etc..
var server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
Run Code Online (Sandbox Code Playgroud)
现在,我知道这个HttpSelfHostServer课程来自System.Web.Http.SelfHost和不使用OWIN,两者都运行良好.
但是我几天来一直在努力实现非常简单的任务,例如使用SSL保护连接,创建授权等等,因为我在这些主题上找到的每个教程都引用了不使用OWIN的自托管方法.但AFAIK,OWIN(Katana)是微软首选实现自托管的方法.
作为一个初学者,我完全困惑和无助!
编辑:仅6分钟即可获得4次赞成,1次收视和30次观看,但仍无法回答.真的不能说我在这里做的是好吃的咖啡还是只是一个令人难以置信的愚蠢问题.
我已经设置了Web Essentials 2013(在Visual Studio 2012中)并加载了默认的Twitter Bootstrap LESS源文件.自动构建和缩小工作完美,除了Web Essentials相当于工作.当我选择" bootstrap.less",进行更改并保存时,Web Essentials会创建一个新的" bootstrap.css"以及" bootstrap.min.css",其中包含我需要的所有内容.但是当我编辑例如buttons.less,它也会创建buttons.css(和buttons.min.css)(包含所有包含和mixins).实际上,这意味着我将在不同的名称下一遍又一遍地使用几乎相同的css文件.
我可以在保存时声明要忽略的某些文件吗?
css less twitter-bootstrap visual-studio-2012 web-essentials
我知道各种教程以及完整的示例目标WebApi和Entity Framework(甚至来自Microsoft)具有这样的WebApi控制器:
public HttpResponseMessage GetInternet(int id) {
var context = new InternetDbContext();
var result =
(from internet in context.Internets
where internet.Id.Equals(id)
select internet).FirstOrDefault();
if(result != null)
Request.CreateResponse(HttpStatusCode.OK, result);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我了解到Entity Framework像2年前,我每次发现对框架资源指出了它是多么极为重要部署了DbContex在最短可能的寿命与"例如using".而现在,人们似乎并没有放弃处理任何东西(他们的经理,存储库,DI容器......).
我在这里错过了什么吗?API调用的结尾是否会自动处理上下文?或者我必须使用HttpRequestMessageExtensions.RegisterForDispose()来自http://msdn.microsoft.com/en-us/library/dn153859(v=vs.118).aspx的内容?
public interface IDatabaseContext : IDisposable {
IDbSet<MyEntity1> Entities1 { get; set; }
}
public class MyDbContext : DbContext, IDatabaseContext {
IDbSet<MyEntity1> Entities1 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
由于此处描述的错误无法编译:http://msdn.microsoft.com/en-Us/library/bb384253(v = vs.90).aspx
然而,由于界面显然是公开的,所以这没有任何意义.这可能是什么错误?
我有一个Windows服务,我使用OWIN和NancyFX来托管一个网站.在我服务的许多地方,我使用Unity将依赖项注入类,主要是服务.但是,如果我在任何Nancy模块中使用它们,依赖关系会被解析两次,因为Nancy使用自己的IoC容器(TinyIoC).
幸运的是,Nancy允许通过创建nancy bootstrapper来覆盖默认的IoC容器生成和现有容器的使用.但是如何将现有的IUnityContainer传递给引导程序?
基本上,我只需要启动OWIN就是......
WebApp.Start<MyOwinStarter>(url);
Run Code Online (Sandbox Code Playgroud)
如何将Unity容器传递给它以将其进一步传递给nancy bootstrapper?
我在申请中声明了以下内容:
[assembly: OwinStartup("MyClass", typeof(MyClass), "ConfigureOwin")]
Run Code Online (Sandbox Code Playgroud)
定义了一个启动类:
public class MyClass {
public void ConfigureOwin(IAppBuilder appBuilder) {
}
}
Run Code Online (Sandbox Code Playgroud)
并开始像这样:
WebApp.Start<MyClass>("baseUri");
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用.WebApp总是试图寻找一个名为"配置"的方法,即使我定义了寻找其他东西.我能做什么?
我从未使用过C++或C++/CLI,但我想在C#项目中使用本机C++库.我用Google搜索了一下,学到了一些关于C++/CLI的东西,并决定给它一个良好的开端.但我不确定我是否做得对.
我struct在本机命名空间中有以下内容:
中avcodec.h
typedef struct AVCodecDescriptor {
enum AVCodecID id;
enum AVMediaType type;
const char *name;
const char *long_name;
int props;
} AVCodecDescriptor;
Run Code Online (Sandbox Code Playgroud)
现在我想将它包装struct在C++/CLI中以便在C#中使用它:
public ref struct AVCodecDescriptorWrapper {
private:
struct AVCodecDescriptor *_avCodecDescriptor;
public:
AVCodecDescriptorWrapper() {
_avCodecDescriptor = new AVCodecDescriptor();
}
~AVCodecDescriptorWrapper() {
delete _avCodecDescriptor;
}
// what do?
property AVCodecID Id {
AVCodecID get() {
return; // what comes here ????
}
}
};
Run Code Online (Sandbox Code Playgroud)
然而,好像我做什么可怕的错误,因为我甚至能看到领域的的struct在C++/CLI AVCodecDescriptor.我必须enum在结构中包装s吗?我是否必须将它们复制到C++/CLI并进行转换(好吧,enum AVCodecID有350个值 …
在Eric Evan的书"领域驱动设计"(人们通常称之为'DDD的最佳示例')中,有很多聚合根(大多数是域模型甚至实体)的例子都满足了某个请求.
我们来看下面的例子:
public Car : IAggregateRoot {
public List<Wheel> Wheels { get; set; }
public void ReplaceWheels();
}
Run Code Online (Sandbox Code Playgroud)
为了更换车轮,我必须从GarageService请求一组新的车轮,车轮本身从WheelRepository收集车轮.在一个场景中,我不是客户,而是替换车轮的车库所有者/机械师,所以打电话很自然:
myCar.ReplaceWheels();
// I'm a domain expert! I have the capabilities to replace the wheels
Run Code Online (Sandbox Code Playgroud)
我的问题是:将WheelService作为聚合根的依赖注入是否正确?或者我应该更好地谈谈WheelService?
public class MyCar : IAggregateRoot {
private readonly IWheelService _wheelService;
public List<Wheel> Wheels { get; set; }
public MyCar(IWheelService wheelService) {
this._wheelService = wheelService;
}
public void ReplaceWheels() {
this.Wheels = _wheelService.getNewSet();
}
}
Run Code Online (Sandbox Code Playgroud)
要么
myWheelService.getNewSet(Car car);
Run Code Online (Sandbox Code Playgroud) 我在我的域中使用了一些不是非常序列化或映射友好的模型,例如System.Net.*命名空间中的结构或类.
现在我想知道是否可以在Entity Framework中定义自定义类型映射.
伪:
public class PhysicalAddressMap : ComplexType<PhysicalAddress>() {
public PhysicalAddressMap() {
this.Map(x => new { x.ToString(":") });
this.From(x => PhysicalAddress.Parse(x));
}
}
Run Code Online (Sandbox Code Playgroud)
期望的结果:
SomeEntityId SomeProp PhysicalAddress SomeProp
------------------------------------------------------------------
4 blubb 00:00:00:C0:FF:EE blah
^
|
// PhysicalAddress got mapped as "string"
// and will be retrieved by
// PhysicalAddress.Parse(string value)
Run Code Online (Sandbox Code Playgroud) 在早期版本的Ninject.Extensions.Conventions中,很容易扫描目录以获取程序集,按接口过滤类,然后加载所有包含ninject模块的类.
kernel.Scan(scanner =>
scanner.FromAssembliesInPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
scanner.AutoLoadModules();
scanner.WhereTypeInheritsFrom<IPlugin>());
public class MyPlugin : NinjectModule, IPlugin {
public override void Load() {
Bind<IRepositoryFromPluginHost>().To<MyPluginImpl>().Named("special");
}
}
Run Code Online (Sandbox Code Playgroud)
然而,在我最近更新到最新版本后,一切似乎都消失了,我无法做到
有人有解决方案吗?