.net Web APIプロジェクトでこのnugetパッケージを使用したかった:https://github.com/Elfocrash/Cosmonaut/tree/885a98151be242516ec57cd94da1747b72588788
4.6.1の.netWeb APIからそのnugetパッケージを使用するというアイデアでしたが、このパッケージはnetstandard 2を対象としているため、nugetパッケージをインストールできませんでした。
最後に、ソースコードをダウンロードし、.net 4.6.1で新しいクラスライブラリを作成しました。これは、完全にコンパイルされます。
次に、.net WebAPIからこのライブラリへの参照を追加しました。
ただし、serviceCollectionがないため、serviceCollectionに問題があります。serviceCollectionを使用するにはどうすればよいですか?
// [Authorize]
public class TenantController : ApiController
{
private CosmosStoreSettings cosmosSettings;
public TenantController()
{
cosmosSettings = new CosmosStoreSettings(ConfigurationManager.AppSettings["database"].ToString(),
ConfigurationManager.AppSettings["endpoint"].ToString(),
ConfigurationManager.AppSettings["authKey"].ToString());
serviceCollection.AddCosmosStore<Book>(cosmosSettings);
}
'serviceCollection'という名前は現在のコンテキストに存在しません
私はそれが何を意味するのかを正確に知っていますが、このプロジェクトにDIを実装する方法がわかりません
使用しているライブラリは、Microsoft.Extensions.DependencyInjection
ASP.NETCoreが使用する依存性注入フレームワークを含むNuGetパッケージを使用しています。ASP.NET Core(.NET Coreでも)に依存していませんが、ASP.NET Web API 2を使用している場合は、シンプルに保ち、ファクトリを作成することをお勧めしますComosStore<T>
。
public static class CosmosStoreFactory
{
private static CosmosStoreSettings _settings = new CosmosStoreSettings("<<databaseName>>", "<<cosmosUri>>", "<<authkey>>");
public static ICosmosStore<T> CreateForEntity<T>() where T: class
{
return new CosmosStore<T>(_settings);
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加