会是怎样一个快速的方法来拷贝/转换一个array的Color32[]值的byte[]缓冲?
Color32是Unity 3D中包含的结构4 bytes, R, G, B and A respectively。我要完成的工作是将渲染的图像从整体通过管道发送到另一个应用程序(Windows Forms)。目前,我正在使用以下代码:
private static byte[] Color32ArrayToByteArray(Color32[] colors)
{
int length = 4 * colors.Length;
byte[] bytes = new byte[length];
IntPtr ptr = Marshal.AllocHGlobal(length);
Marshal.StructureToPtr(colors, ptr, true);
Marshal.Copy(ptr, bytes, 0, length);
Marshal.FreeHGlobal(ptr);
return bytes;
}
Run Code Online (Sandbox Code Playgroud)
谢谢,抱歉,我是StackOverflow的新手。Marinescu Alexandru
我正在使用ASP.NET MVC 4应用程序.
家庭控制器的构造函数参数化为2参数(Iservice1 service1,Iservice2 service2)并非所有代码路径都使用任何Service(service1,service2),只在某些代码路径中我需要service1 instance/object或service2 instance/object.
我不想使用container.Resolve < <Lazy<IService1>>();
从这个链接(http://msdn.microsoft.com/en-us/library/dn178463(v=pandp.30).aspx)我明白unity.mvc 4使用unity 3,它具有Lazy loading支持,但是如何在ASP.NET MVC 4中执行此操作.
asp.net-mvc lazy-loading inversion-of-control unity-container deferred-loading
最新版本的SimpleInjector引入了MVC和WebApi之间的区别.两个请求注册是否为同一个东西的别名?或者是否存在潜在的差异?
谢谢
我想通过 SimpleInjector 注入 Container 属性。我没有找到 SimpleInjector 的任何功能。
然后我想将self Container注册到自己,但是Container没有接口。
我想要这个功能,因为我不通过构造函数传输 Container 对象 - 因为如果我可以使用注册对象的自动注入。
我的使用思路:
var container = new Container();
container.Options.AutowirePropertiesWithAttribute<InjectableProperty>();
container.Register<ISomething, Something>(Lifestyle.Singleton);
Run Code Online (Sandbox Code Playgroud)
ISomething:
public interface ISomething
{
void SomeMethod();
}
Run Code Online (Sandbox Code Playgroud)
东西类:
public class Something : ISomething
{
public void SomeMethod()
{
var environment = _container.GetInstance<IEnvironment>();
environment.DoSomething();
}
[InjectableProperty] // - maybe it is not possible (I don't know it)
Container Container {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
你有什么想法来实现这一目标吗?
非常感谢。
我有一种情况,我想使用Identity框架中的自定义UserStore.所以我的控制器看起来像这样.
public AccountController()
: this(new UserManager<ApplicationUser>(new MyUserStore()))
{
}
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
}
Run Code Online (Sandbox Code Playgroud)
现在Simpleinjector不允许多个构造函数.它可以允许用一个构造函数注册这些类.当情况与上述情况类似时,我该如何解决这个问题.使用Simpleinjector注册.
asp.net-mvc dependency-injection simple-injector asp.net-mvc-4 asp.net-identity
我将.png(800 x 294)尺寸37.2 KB导入统一但导入后显示它的大小为0.9MB,这比原来的大.我在导入设置中将最大尺寸更改为1024到512,将分辨率从原始尺寸降低到512 x 188,尺寸为94KB.如果没有任何图像分辨率变化,.png大小如何增加(从37.2K到0.9MB)?
我希望能够将装饰器与Autofac混合搭配.
例如,假设我有一个由Repository类实现的IRepository接口.
我可以拥有以下装饰器:RepositoryLocalCache,RepositoryDistributedCache,RepositorySecurity,RepositoryLogging ...,你得到了ideea.
基于配置设置,我想用所需的装饰器来装饰基本实现.那可以是无,一个或多个装饰器.
我熟悉注册一个装饰器的语法,或者按固定顺序注册它们的链,但我怎样才能使这个动态化呢?
我以前在我的一个属性中设置了属性注入设置
Container.RegisterInitializer<PermitAttribute>(initialize =>
{
initialize.QueryProcessor = Container.GetInstance<IQueryProcessor>();
});
Run Code Online (Sandbox Code Playgroud)
用法是
public class PermitAttribute : ActionFilterAttribute
{
public IQueryProcessor QueryProcessor { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但在更新到simpleinjector之后2.6.1属性注入破了.当我试图访问QueryProcessorPermitAttribute内的对象时.它解析了null值,因为Simple Injector配置仍然通过委托实例注入相同的属性.
由于它在v2.5中工作并且在2.6.1中不再起作用,属性注入行为是否有任何重大变化?
更新1:
配置中的Line为MVC过滤器提供程序注册v2.6.1中的属性引发了错误
container.RegisterMvcIntegratedFilterProvider();
Run Code Online (Sandbox Code Playgroud)
为此我评论了它.它阻止了房产注入工作.属性注入是我的一个属性.我猜这就是影响它的线.它在v2.6.1中抛出错误
更新2:
信息
已为另一个Container实例注册了MVC筛选器提供程序.此方法不支持为不同容器注册MVC筛选器提供程序.
堆栈跟踪 :
at SimpleInjector.SimpleInjectorMvcExtensions.RequiresFilterProviderNotRegistered(Container container)
at SimpleInjector.SimpleInjectorMvcExtensions.RegisterMvcIntegratedFilterProvider(Container container)
at RemsPortal.App_Start.SimpleInjectorInitializer.Initialize() in d:\Projects Work\RemsPortal\V2.0 Web Portal\RemsPortal\App_Start\SimpleInjectorInitializer.cs:line 39
Run Code Online (Sandbox Code Playgroud)
更新3:
整个配置
public static void Initialize()
{
var container = new Container();
InitializeContainer(container);
container.RegisterMvcIntegratedFilterProvider();
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
}
private static void InitializeContainer(Container Container)
{
Container.RegisterManyForOpenGeneric(typeof(IAsyncCommandHandler<,>),
AppDomain.CurrentDomain.GetAssemblies());
Container.RegisterOpenGeneric(typeof(ITransactionCommandHandler<,>),
typeof(TransactionCommandHandlerDecorator<,>)); …Run Code Online (Sandbox Code Playgroud) 所以,我在团结中使用C#来使用Unity UI放置一些对象,并且我有一个对象,其在脚本中的位置与它在场景中的位置不同.我在函数中有以下代码:
using UnityEngine;
using System.Collections;
public class SeedChecker : MonoBehaviour {
Vector3 lockedPos;
RectTransform tran;
// Use this for initialization
void Awake () {
tran = GetComponent<RectTransform>();
}
public void LockPos(Vector3 pos) {
tran.localPosition = pos;
lockedPos = pos;
print (tran.localPosition);
}
}
Run Code Online (Sandbox Code Playgroud)
例如,此代码打印其x位置为-60 - 这是我正在寻找的正确数字 - 屏幕中间左侧60个像素.但是,当我查看检查器和场景时,x位置为0 - 并且对象正好位于屏幕中间.这是一个相当令人沮丧的情况,我在这里也谈过这个问题.这令人沮丧,因为它说它正在获得正确的位置,但是当我将这个正确的位置分配给对象时,它会转到我认为不正确的位置.这是对RectTransforms中localposition如何工作的误解吗?我的对象是一些对象的子对象,但是它们全部归零到屏幕的中心,并且对于缩放值具有"1".
似乎直到Dispose在控制器作用域中解析的元素上调用之前,执行上下文都不会保留。这可能是由于asp.net核心必须在本机代码和托管代码之间跳转,并在每次跳转时重置执行上下文。似乎在处置范围之前不再恢复正确的上下文。
以下内容演示了该问题-只需将其放入默认的asp.net核心示例项目中并注册TestRepo为临时依赖项即可。
调用时,GET api/values/我们在调用开始时在静态AsyncLocal中将当前任务的值设置为5。该值按预期方式流动,毫无问题。但是,在调用之后处置控制器及其依赖项时,AsyncLocal上下文已被重置。
[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly TestRepo _testRepo;
public ValuesController(TestRepo testRepo) => _testRepo = testRepo;
[HttpGet()]
public async Task<IActionResult> Get()
{
_testRepo.SetValue(5);
await Task.Delay(100);
var val = _testRepo.GetValue(); // val here has correctly 5.
return Ok();
}
}
public class TestRepo : IDisposable
{
private static readonly AsyncLocal<int?> _asyncLocal = new AsyncLocal<int?>();
public int? GetValue() => _asyncLocal.Value;
public void SetValue(int x) => _asyncLocal.Value = x;
public void …Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net-mvc ×3
.net ×2
.net-core ×1
asp.net-core ×1
autofac ×1
containers ×1
copy ×1
lazy-loading ×1
marshalling ×1
sprite ×1
struct ×1
transform ×1